git flow
install
$ brew install git-flow
git flow
usage: git flow
Available subcommands are:
init Initialize a new git repo with support for the branching model.
feature Manage your feature branches.
release Manage your release branches.
hotfix Manage your hotfix branches.
support Manage your support branches.
version Shows version information.
Try 'git flow help' for details.
git flow init
Which branch should be used for bringing forth production releases?
- master
Branch name for production releases: [master]
Branch name for "next release" development: [develop] dev
How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? [] v
git flow feature
feature ブランチの流れ
#機能追加を始めますよ
$ git flow feature start [-F] []
#編集してコミットする
$ git commit -a -m 'add code'
$ git checkout dev && git pull
$ git checkout feature feature/
#機能追加完了
$ git flow feature finish [-rFkDS] [] # -k で branchが消えない
#pull
$ git pull
#リモートのdevブランチにpush
$ git push
git flow feature で使えるコマンド
git flow help
git flow feature [list] [-v]
git flow feature start [-F] []
git flow feature finish [-rFkDS] []
git flow feature publish
git flow feature track
git flow feature diff []
git flow feature rebase [-i] []
git flow feature checkout []
git flow feature pull [-r] []
git flow hotfix
git flow hotfix start [-F] []
working...
$ git add
$ git commit
$ git checkout dev && git pull # 最新にしとく
$ git checkout master && git pull # 最新にしとく
$ git flow hotfix finish [-Fsumpk]
# master と dev にマージされてtagができるから
git flow hotfix で使えるコマンド
finishするまでの間にmasterが更新された場合は諦めてマージするのが正しい
pull --rebaseもNG
fetch & rebaseだからね
rebaseはcommitIDを変える
dev, masterが古かったことに気付いたときは、一旦dev, masterをcheckoutし直してfinishをやり直すと言う方法もある
(git flow hotfix finish -k hogeでhotfixブランチを残しておけばそれも可能)
※masterを更新しわすれたりしたとき
$git fetch; git rebase -p origin/master
-pはhotfixのマージコミットを残す。
# dev
git fetch; git rebase -p origin/dev
git flow release
#devブランチとmasterブランチを最新化しておく
$ git pull
#devブランチでsubtreeをpullする (最新化する)
$ git subtree pull --prefix=shared git@github.com:yanap/frma-shared.git master
#pushする
$ git push
#リリースブランチをはじめる
$ git flow release start 1.0.1
#リリースブランチをおわる
$ git flow release finish 1.0.1
#タグを確認する
$ git tag -n
#pushする
$ git push origin master
$ git push origin v1.0.1
#途中コンフリクトがおきたとき
$ git checkout --theirs
$ php -l
$ git add
$ git commit
#でなおして途中で終了してしまうので消してやり直すかcheckoutしなおして finishからやり直す
参考
見えないチカラ: A successful Git branching model を翻訳しました
successful Git branching model を補助する git-flow を使ってみた - Twisted Mind
ぼくが実際に運用していたGitブランチモデルについて ::ハブろぐ