git branch

git

書き方

git branch [-a|-vv] [-d <name>]

ブランチを並べ、作り、消します。消してもリモートには残るので、サーバー側はgit push origin --deleteが別に必要です。

よく使うオプション

オプション意味
-alocal and remote-tracking branches
-rremote-tracking branches only
-vvlast commit and upstream of each branch
-d <name>delete a branch that is already merged
-D <name>delete it even if unmerged; those commits are left behind
-m <old> <new>rename
--mergedbranches already contained in the current one
--show-currentprint the branch you are on

git branch -vv

every local branch with its upstream and last commit

git branch -d old-feature

removes a merged branch locally only

git push origin --delete old-feature

the separate step that removes it on the server

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git branch は何をしますか。

ブランチを並べ、作り、消します。消してもリモートには残るので、サーバー側はgit push origin --deleteが別に必要です。

Q. どう打ちますか。

git branch [-a|-vv] [-d <name>] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは8個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-branch