使い方メモ書き。
Git Flow は git で開発するに当たって、ブランチモデルを補助するための拡張です。
2013/04/20 追記更新
サブコマンドに push/pull 追加
てか Gitflow cheatsheet を読んだほうが、コレ読むより速い。
Install
$ brew install git-flow
その他は Gitflow wiki を参考
使い始める
リポジトリの開発方針を決めます。既存のリポジトリにも使用可能
$ git flow init
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop]
How to name your supporting branch prefixes?
Feature branches? [feature/] Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
2 つのメインブランチ develop
と master
が作成されます。
- master: svn で言う trunk に当たります
- develop: 開発用ブランチ。リリース準備ができれば、
release
を使用し masterへマージします。
その他にも feature
, release
, hotfix
, support
を使うことができます。
feature
, release
, hotfix
, support
は開発や作業を切り分けたい時に使用します。
切り分ける時は hoge start ~~
で切り分けることができ、 hoge finish ~~
で develop
ブランチにマージする事ができます。
Feature を使う
プロジェクトに新しく機能を追加したいとなった時、feature
を使います。
feature
で開発をはじめる時は feature start ~~
で開始し、 feature finish ~~
で終わります。
$ git flow feature start test
Switched to a new branch 'feature/test'
Summary of actions:
- A new branch 'feature/test' was created, based on 'develop'
- You are now on branch 'feature/test'
Now, start committing on your feature. When done, use:
git flow feature finish test
$ git branch
develop
* feature/test
master
例えば、 test.py というファイルを作成し、適当なプログラムを書いて ok とします。
$ git add test.py
$ emacs test.py
…
$ git commit -a -m 'add test.py
quote> '
[feature/test 3b4b475] add test.py
1 files changed, 8 insertions(+), 0 deletions(-)
create mode 100644 test.py
他人に変更を知らせたい場合などあります。大体は中央リポジトリにpushしたりします。その場合はこんな感じで push をします。
$ git flow feature publish test
もしくは他人の変更を取得したい場合はこんな感じ
$ git flow feature pull test
これで新機能の追加が終わりましたので、finish
をします。
$ git flow feature finish test
Switched to branch 'develop'
Updating 42483eb..3b4b475
Fast-forward
test.py | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
create mode 100644 test.py
Deleted branch feature/test (was 3b4b475).
Summary of actions:
- The feature branch 'feature/test' was merged into 'develop'
- Feature branch 'feature/test' has been removed
- You are now on branch 'develop'
Release する
develop
にて必要機能が出来たとします。それを master
にマージさせ、リリースした状態にします。
$ git flow release start 1.0
Switched to a new branch 'release/1.0'
Summary of actions:
- A new branch 'release/1.0' was created, based on 'develop'
- You are now on branch 'release/1.0'
Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:
git flow release finish '1.0'
追記やREADMEなどを書きます。多分…
$ git commit -a -m 'release'
$ git flow release finish 1.0
Switched to branch 'master'
Merge made by the 'recursive' strategy.
test.py | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
create mode 100644 README.md
create mode 100644 test.py
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
Deleted branch release/1.0 (was feef19f).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch has been merged into 'master'
- The release was tagged '1.0'
- Release branch has been back-merged into 'develop'
- Release branch 'release/1.0' has been deleted
これで master
には 1.0 のリリースタグが付きました。
Hot fix を使う
master
にて、バグなどが見つかったとします。その時は hotfix
で切り分けます。
開発方法は feature
と同じです。
$ git flow hotfix start test-typo
Switched to a new branch 'hotfix/test-typo'
Summary of actions:
- A new branch 'hotfix/test-typo' was created, based on 'master'
- You are now on branch 'hotfix/test-typo'
Follow-up actions:
- Bump the version number now!
- Start committing your hot fixes
- When done, run:
git flow hotfix finish 'test-typo'
$ git branch
develop
* hotfix/test-typo
master
$ emacs test.py
…
$ git commit -a -m 'typofix'
[hotfix/test-typo 70e26d5] typofix
1 files changed, 1 insertions(+), 1 deletions(-)
$ git flow hotfix finish 'test-typo'
Switched to branch 'master'
Merge made by the 'recursive' strategy.
test.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
test.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
Deleted branch hotfix/test-typo (was 70e26d5).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Hotfix branch has been merged into 'master'
- The hotfix was tagged 'test-typo'
- Hotfix branch has been back-merged into 'develop'
- Hotfix branch 'hotfix/test-typo' has been deleted
$ git tag -n
1.0 Release
test-typo miss...
サブコマンド「publish」/「pull」は、コマンド feature/hotfix/release などで使用できるみたいです。