Pull Requestをレビューする時に、リモートリポジトリからレビュー対象のブランチを探してチェックアウトして、すでにチェックアウトしてたらpullして・・・という一連の作業を効率化したいと思い、ローカルのすべてのbranchの状態をリモートと一致させるfunctionを作ってみた。
ちょっとおおざっぱすぎるかなという気がするけど、しばらく使ってみよう。
function git-checkout-remote-all(){ for remote_branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do remote_name="$(echo -n "$remote_branch" | cut -d/ -f2)" branch_name="$(echo -n "$remote_branch" | cut -d/ -f3-)" git checkout -b $branch_name $remote_name/$branch_name git checkout $branch_name git pull done }