2012年11月6日火曜日

【git】ブランチの作成

【ブランチを一覧表示】

 git branch          (ローカルに存在するブランチのみ表示)
 git branch -a         (ローカルとリモート全てに存在するブランチが表示)



【ローカルブランチの作成と切替(チェックアウト)】

 git branch [作成ブランチ名]
 git checkout [作成ブランチ名]


(例)

 (1) ローカルの「develop」から「feature」ブランチを作成して切替

   git checkout -b feature-2.2.1 develop

    ※「-b」は「git branch」のショートカット



 (2)「feature-2.2.1」というローカルブランチを、リモートの「origin/develop」から作成して切替

   git checkout -b feature-2.2.1 remotes/origin/develop



【ブランチのマージ】

 git checkout [マージ先ブランチ名]
 git merge [--no-ff] [マージしたいブランチ名]

(例)
  ローカルのdevelop に feature-2.2.1 をマージしたい場合

    git checkout develop
    git merge --no-ff feature-2.2.1



【マージ済みのブランチ一覧を表示】

  git branch --merged

【マージされていないブランチ一覧を表示】

  git branch --no-merged

【ブランチの削除】

  git branch -d [ブランチ名]

   ※マージ済みでない(作業が残っている)ブランチは「-d」で削除できない。
   ※強制削除したい場合は大文字「git branch -D」で削除




【ブランチ名を変更】

 git branch -m [新ブランチ名]


【既存のブランチ名に上書き変更】
 git branch -M [新ブランチ名]