LoginSignup
6
7

More than 5 years have passed since last update.

GitHub | Command Line で GitHub を操作する hub の基礎

Posted at

:musical_score: 概要

Command Line で GitHub を操作する hub の基礎

:question: hub とは?

git コマンドに GitHub とのやり取りを便利にするコマンドを追加します。
これにより、GitHub を利用した開発の効率があがります。

Images

:baby_chick: Before

:turtle::point_right:
:walking:
:walking:
:walking:
:turtle::point_right::octocat:
:walking:
:walking:
:walking:
:turtle::point_right:

:chicken: After

:rabbit::point_right::octocat:
:rabbit::point_right::octocat:

Installation

バイナリをダウンロードして、パスが通った場所に配置します。

hub 2.2.0-rc1

Confirm Installation

機能の確認がてら、 help command で動作確認をします。

$ hub help | tail -12

GitHub Commands:
   pull-request   Open a pull request on GitHub
   fork           Make a fork of a remote repository on GitHub and add as remote
   create         Create this repository on GitHub and add GitHub as origin
   browse         Open a GitHub page in the default browser
   compare        Open a compare page on GitHub
   release        List or create releases (beta)
   issue          List or create issues (beta)
   ci-status      Show the CI status of a commit

See 'git help <command>' for more information on a specific command.

Settings

alias の追加

hub を利用する際は、 alias によって git command として扱います。
これにより、 git command は今まで通り利用しつつ、
hub の機能を追加することができます。

.bashrc などに下記設定を追加します。

eval "$(hub alias -s)"
  • git command を呼び出して、 hub の機能が追加されたことを確認します
$ . ~/.bashrc
$ git help | tail -12

GitHub Commands:
   pull-request   Open a pull request on GitHub
   fork           Make a fork of a remote repository on GitHub and add as remote
   create         Create this repository on GitHub and add GitHub as origin
   browse         Open a GitHub page in the default browser
   compare        Open a compare page on GitHub
   release        List or create releases (beta)
   issue          List or create issues (beta)
   ci-status      Show the CI status of a commit

See 'git help <command>' for more information on a specific command.

サブコマンドの入力補完を設定

bash, zsh の入力補完がサポートされています。
bash の場合は、下記を .bashrc に設定します。

$ wget -O ~/.hub.bash_completion.sh https://raw.githubusercontent.com/github/hub/master/etc/hub.bash_completion.sh

これで、git / hub のコマンドを補完可能になりました。

デモ

私の自作 gem である tbpgr_utils の Issue を取得してみます。1
git i 後に、タブを入力してコード補完を呼び出していることを確認できます。

hub_issue.gif

:books: 脚注


  1. tbpgr_utils は実用 gem ではない 

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7