githubに「pull request」を送れたりするhubコマンドを導入方法をメモ

hubコマンドはGitHub社が公開しており、githubに関する様々な処理をコマンドで実行する事ができるもの。
gitコマンドで既にできることを、シンプルなコマンドで解決したり、gitコマンドではないpull requestなどをコマンドで行う事ができるようになる。
※ 通常はgithubのブラウザからpull requestをする

またhubはgitコマンドを包括しており、hubコマンドでgitコマンドを全て使用することができるようになる。

hubのupstreamリポジトリのreadmeでインストールからコマンドの使い方まで載せているので参考にするとよい。

hubコマンドのリポジトリ:
https://github.com/github/hub

今回はmacでパッケージ管理はhomebrewを使用する

インストール

インストール

brew install --HEAD hub

設定

既存のgitコマンドは全てhubに置き換えられるようになる。
つまりは

git add .

hub add .

で、できるようになるが、慣れないためhubコマンドもgitコマンドで使えるようにalias設定をしておく
これはhubのreadmeに記載されている

シェルの設定ファイル:

eval "$(hub alias -s)"

※bashの場合は.bash_profile、zshの場合は、.zprofile

hubの使い方(git clone)

git cloneコマンドについてreadmeより、

git clone

$ git clone schacon/ticgit
> git clone git://github.com/schacon/ticgit.git

$ git clone -p schacon/ticgit
> git clone git@github.com:schacon/ticgit.git

$ git clone resque
> git clone git@github.com/YOUR_USER/resque.git

※gitはalias設定のhubをコールしているため、hubとしても動く

git cloneを行う場合にgithubのリポジトリ指定をなしにしてリポジトリ名のみで取得ができる。またはユーザ名の指定などもできるサンプル

これ以外にも省略できるコマンドはreadme参照

hubコマンドでpull request

git pull-requestコマンドについてreadmeより

# while on a topic branch called "feature":
$ git pull-request
[ opens text editor to edit title & body for the request ]
[ opened pull request on GitHub for "YOUR_USER:feature" ]

# explicit title, pull base & head:
$ git pull-request -m "Implemented feature X" -b defunkt:master -h mislav:feature

オプションについて
-m : pull requestメッセージ
-b : プルリク先の指定
-h : プルリク元の指定

下記はつまり、メッセージが「Implemented feature X」でmislavのfatureブランチからdefunktのmasterブランチへpull requestのサンプルになる

git pull-request -m "Implemented feature X" -b defunkt:master -h mislav:feature

-mを指定しない場合は、指定しているエディターが起動する(commitと同様)ので指定のフォーマットで記載する

指定フォーマット:
[pull requestタイトル]
[改行]
[pull requestメッセージ]

使える便利コマンド

githubをブラウザで開いてリポジトリを参照するコマンド

git browse

githubをブラウザで開いてdiffを参照するコマンド

git compare

git compareコマンドについてreadmeより

$ git compare refactor
> open https://github.com/CURRENT_REPO/compare/refactor

$ git compare 1.0..1.1
> open https://github.com/CURRENT_REPO/compare/1.0...1.1

$ git compare -u fix
> (https://github.com/CURRENT_REPO/compare/fix)

$ git compare other-user patch
> open https://github.com/other-user/REPO/compare/patch

その他おすすめの備忘録

Tagged with:
 

コメントを残す