Gitクローンしたい(ghq
)
$ brew install ghq
$ ghq --version
ghq version 1.4.2 (rev:7163e61)
$ ghq get git@github.com:shotakaha/kumaroot.git
$ ghq get shotakaha/kumaroot
$ ghq get kumaroot
ghq
はgit clone URL
を簡単にしてくれるコマンドです。
GitHubからクローンする場合は、ユーザー名リポジトリ名
だけ指定してもOKです。
ユーザー名を省略した場合は、(おそらく)ghq
コマンドを実行したユーザー名が適用されます。
注釈
デフォルトはhttps
でクローンします。
SSH
したい場合は-p
オプションを追加します。
リポジトリをクローンしたい(ghq get
)
$ ghq get git@github.com:shotakaha/kumaroot.git
Cloning into '~/repos/github.com/shotakaha/kumaroot'...
ghq get
コマンドで、ghq.root
で設定したパスの下に、リポジトリのURLに沿った形式でクローンできるようになります。
どのディレクトリで実行してもOKなのも、このコマンドが便利な点です。
$ ghq get shotakaha/kumaroot
exists /Users/shotakaha/repos/github.com/shotakaha/kumaroot
すでにクローンしてあるプロジェクトを指定した場合は、 クローン済であることを教えてくれます。
注釈
ブランチ/タグを指定したり、クローン先のディレクトリ名を変えたい場合は、 素直にgit cloneのオプションを使うのがよさそうです。
リポジトリを更新したい(ghq get -u
)
$ ghq get -u リポジトリ名
$ ghq get -u shotakaha/kumaroot
update ~/repos/github.com/shotakaha/kumaroot/
git pull --ff-only
...
-u, --update
オプションを使って、リポジトリを更新できます。
内部でgit pull --ff-only
しているようです。
デフォルトディレクトリを設定したい
$ git config --global ghq.root "~/repos/"
git config
コマンドを使ってghq.root
を変更できます。
デフォルトでは~/ghq
に設定されています。
ヒント
ghq
コマンドは、僕の使い方にとてもマッチしていたツールでした。
このコマンドを知る以前は、同じようなことを手動でやっていました。
Gitリポジトリはすべて
~/repos/
の下で管理GitHubは
~/repos/github/
の下にクローンGitLabは
~/repos/gitlab/
の下にクローン上記のクローンするパスは自分で指定
また、動作確認したいリポジトリは~/repos/sandbox/
の下にクローンして、いつでも使い捨てられるようにしているのですが、この使い方に並行してghq
コマンドを導入できました。
リポジトリを確認したい(ghq list
)
$ ghq list
github.com/Geant4/geant4
github.com/RedPitaya/RedPitaya
github.com/gohugoio/hugo
github.com/shotakaha/kumaroot
github.com/shotakaha/zenn-docs
github.com/typst/typst
gitlab.com/qumasan/haniwers
sandbox/getting-started
sandbox/hugo-quickstart
sandbox/hugo-sandbox
ghq list
でクローンしたリポジトリのパスを表示できます。
注釈
ghq
を使ってクローンしたかどうかに関係なく、ghq.root
で指定したディレクトリにあるリポジトリがすべて表示されます。
$ ghq list 検索文字列
$ ghq list shotakaha
github.com/shotakaha/hugo_sandbox
github.com/shotakaha/kumaroot
github.com/shotakaha/zenn-docs
gitlab.com/shotakaha/brewfile
gitlab.com/shotakaha/cv
ghq list
コマンドの引数に検索文字列を指定できます。
管理しているリポジトリが多い場合は、ユーザー名やプロジェクト名(の一部)で絞り込むことができます。