git branch
git
書き方
git branch [-a|-vv] [-d <name>]ブランチを並べ、作り、消します。消してもリモートには残るので、サーバー側はgit push origin --deleteが別に必要です。
よく使うオプション
| オプション | 意味 |
|---|---|
| -a | local and remote-tracking branches |
| -r | remote-tracking branches only |
| -vv | last 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 |
| --merged | branches already contained in the current one |
| --show-current | print the branch you are on |
例
git branch -vvevery local branch with its upstream and last commit
git branch -d old-featureremoves a merged branch locally only
git push origin --delete old-featurethe 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