ブランチの表示
ローカルブランチの確認
【コマンド】
git branch
【実行例】
$ git branch
* master
リモートブランチの確認
【コマンド】
git branch -r
【実行例】
$ git branch -r
origin/master
ローカル・リモート両方のブランチを表示
- リモートブランチにはprefixとしてremotesが表示される。
【コマンド】
git branch -a
【実行例】
$ git branch -a
* master
remotes/origin/master
ブランチの作成
- 派生元ブランチを省略した場合現在のブランチの先頭から新しいブランチを派生する。
- 当然であるが全てのブランチには必ず派生元のブランチが存在する。
- 作成したブランチのリモートリポジトリへの反映には別途pushコマンドを実行する。
【コマンド】
git branch <ブランチ名> <派生元ブランチ名>
【実行例】
$ git branch testBranch
$ git branch
* master
testBranch
- リモートのdevブランチをもとにlocalにdevブランチを作成
【実行例2】
$ git branch dev remotes/origin/dev
Branch 'dev' set up to track remote branch 'dev' from 'origin'.
$ git branch -a
dev
* master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/master
作業ブランチの変更
【コマンド】
git checkout <ブランチ名>
【実行例】
$ git branch //現在のブランチを確認
* master
testBranch
$ git checkout testBranch //ブランチの変更
Switched to branch 'testBranch'
$ git branch //ブランチが変更されたことの確認
master
* testBranch
リモートブランチへの反映
【コマンド】
$ git push <リモートリポジトリ> <ブランチ名>
【実行例】
$ git push origin dev
Total 0 (delta 0), reused 0 (delta 0)
To https://***@github.com/okn-yu/Nand2Tetris.git
* [new branch] dev -> dev
ブランチの削除
【コマンド】
git branch -d <ブランチ名>
【実行例】
$ git branch -d testBranch
Deleted branch testBranch (was 4d25679).
$ git branch
* master