u++の備忘録

gitでremote repositoryの特定のbranchをlocalに落とす

自分用のメモ。

Pull Requestのレビュー時など、過去のコマンドから都度漁っていたので、まとめておく。

gitコマンド

git fetch --prune
git branch -r
git ch -b local-name origin/remote-name

説明

git fetch --prune

  • remote repositoryからデータを取得
  • --pruneオプションを付けて、remote repositoryで削除されているbranchを削除する

git branch -r

  • remote branchの一覧を表示
  origin/HEAD -> origin/master
  origin/feature-hoge
  origin/feature-fuga
  origin/feature-piyo

git ch -b local-name origin/remote-name

  • chはcheckoutのエイリアス
  • 特定のremote branch(origin/remote-name)の内容で、local branch(local-name)を切る
  • -bオプションを付けて、branchを切り替える