Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

GitHubをCLIから操作する「hub」コマンドの導入

f:id:tbpg:20151030020103j:plain

GitHubCLIから操作する「hub」コマンドの導入

インストール

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

github/hub - GitHub

基本機能

Helpを確認

Remote Commands:
   clone      Clone a remote repository into a new directory
   fetch      Download data, tags and branches from a remote repository
   pull       Fetch from and merge with another repository or a local branch
   push       Upload data, tags and branches to a remote repository
   remote     View and manage a set of remote repositories

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.

以下、2コマンドだけ抜粋して動かしてみます

git issue

hkdnetさんのGitRec repositoryのissueを確認してみましょう。

$ cd %GitRec Home%
$ git issue
     13] 構造を変える ( https://github.com/hkdnet/GitRec/issues/13 )
     12] MIMEをmultipartにする ( https://github.com/hkdnet/GitRec/issues/12 )
      9] Rakefileでビルド失敗時に止まらない ( https://github.com/hkdnet/GitRec/issues/9 )
      2] masterのログしかとれない? ( https://github.com/hkdnet/GitRec/issues/2 )

git browse

hkdnetさんのGitRec repositoryを開いてみましょう。

$ cd %GitRec Home%
$ git browse

f:id:tbpg:20151030020315p:plain

※気になるリポジトリですね。今後に期待。

gitのaliasの設定を追加

bashZsh単体で利用している場合は、.bashrcや.zshrcに設定を追加しますが、今回はzsh+prezto環境に設定を追加してみます。

  • ~/.zpreztorc
# 追加
function git(){hub "$@"} # zsh

iTerm2 + Powerlineを併用している場合

ブランチ表示に対応しているPowerlineなどを利用している場合は、表示が遅くなってしまうため以下の設定が必要です。

~/.zprezto/modules/prompt/functions/prompt_powerline_setup に設定を追加

# prompt_poswerline_precmd関数の直下に追加する
function prompt_powerline_precmd {
  # 以下の設定を追加
  local git==git

外部資料