LoginSignup
8
8

More than 5 years have passed since last update.

git flow してみた

Last updated at Posted at 2015-01-20

はじめに

開発が混み合ってきたので、git flowをいれてみました。
備忘録的なメモです。
間違っていたらつついてくださると助かります。

環境・条件

  • CentOS 6.4
  • MacOSX 10.10

  • Githubなどにリポジトリを持っていて、そこへpushしていきます。

  • CIを使って、それぞれのbranchへのpushをhookして、別々の環境にdeployされます。
    -- develop -> staging
    -- master -> production

install

$ sudo yum install gitflow # yum
$ brew install gitflow # brew

とりあえずやってみる

事前に

masterブランチをローカルに作っておいて、最新状態にしておくといいです。
push, pullしきっておくといいです。
(developブランチは作っておいてもいいようですが、詳細は調べきれてないです)

init

$ git flow init

Which branch should be used for bringing forth production releases?
   - master
Branch name for production releases: [master] master

Which branch should be used for integration of the "next release"?

Branch name for "next release" development: [develop] develop

How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []

init させるといろいろきかれます。
特にこだわりがなければ、何も入力せずreturn連打でいいかと思います。

ブランチ切って作業開始

Githubのissueに対応毎にブランチ切る感じがいいようです。
fooとかはbranch名としてはヽ(´Д`ヽ)(/´Д`)/イヤァ~なので、
作業内容をうまく表現した名前にしてみるといいかもしれません。

$ git flow feature start foo
Switched to a new branch 'feature/foo'

Summary of actions:
- A new branch 'feature/foo' was created, based on 'develop'
- You are now on branch 'feature/foo'

Now, start committing on your feature. When done, use:

     git flow feature finish foo

ふんふん、developを元にfoo branchが作られたみたいです。
あ、チェックアウトまでしてくれている。

$ git branch
  develop
* feature/gitflowtest
  master

つまり↓みたいな感じですかね?

$ git checkout -b feature/foo

をしてくれたのかな?

作業の前にはまずpull

誰かがGithubにpushして、差分が発生した場合、HEADのものをfeature/fooにpullします。

$ git flow feature pull origin

commit してみる

$ git status
# On branch feature/foo
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   test.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -am "[add] i did hogehoge test #1"

1 はGithubのissue #1 に対応した場合に書くといい感じです。

issueにコミット内容が連携されます。

commitをして作業が終わったら

$ git status
# On branch feature/foo
nothing to commit (working directory clean)
$ git flow feature finish foo
Switched to branch 'develop'
Updating 6e234bf..132ba7e
Fast-forward
 test.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Deleted branch feature/foo (was 132ba7e).

Summary of actions:
- The feature branch 'feature/foo' was merged into 'develop'
- Feature branch 'feature/foo' has been removed
- You are now on branch 'develop'
$ git branch
* develop
  master

おー!
developにマージして、branchを消してくれたみたいです。

つまり↓でしょうか?

$ git checkout develop
$ git merge feature/foo
$ git branch -d feature/foo

commitしてないと

$ git flow feature finish foo
fatal: Working tree contains unstaged changes. Aborting.

devとかstagingとかにあげてみる(共有リポジトリにpush)

基本はdevelop一本で問題ないかと思うので、developのみをpushします。

$ git push origin develop

今回の場合は、これでciがdev環境にpushされます。

branchを他のメンバーと共有する場合やpull requestがいる場合

git flow feature finish foo をヤる前に

$ git flow feature publish foo

をすると、branch毎pushされる様です。

Github側に feature/foo ブランチが生成されます。

でGithub側でpullrequestなど操作します。
諸々作業が終わったらGithubでも、ローカルでもbranchは消すといいかと思います。

$ git flow feature finish foo

releaseしてみる。本番化プロセス

release branchを切って作業開始

$ git flow release start v0.0.1
Switched to a new branch 'release/v0.0.1'

Summary of actions:
- A new branch 'release/v0.0.1' was created, based on 'develop'
- You are now on branch 'release/v0.0.1'

Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:

     git flow release finish 'v0.0.1'
$ git branch
  develop
  master
* release/v0.0.1

やってることはfeature startのとことあんまり変わらないですね。

developからrelease/v0.0.1 がつくられていますから、最新の状態には変わりないです。
本番環境で必要なことなど、何かあればcommit します。

作業終了。いろいろ起きます。

git flow release finish v0.0.1を叩くとすぐに、tagを何にするか聞かれます。そこで適切なtagを入力するといいかと思います。

$ git flow release finish v0.0.1
Branches 'develop' and 'origin/develop' have diverged.
And local branch 'develop' is ahead of 'origin/develop'.
Switched to branch 'master'
Merge made by recursive.
 test.txt |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Deleted branch release/v0.0.1 (was 60da76a).

Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch has been merged into 'master'
- The release was tagged 'v0.0.1'
- Release branch has been back-merged into 'develop'
- Release branch 'release/v0.0.1' has been deleted

↑やった内容がしっかり書かれていていいですね。
つまり、こういうこと↓でしょうか?

$ git checkout master
$ git merge release/gitflowtest
$ git tag v0.0.1
$ git checkout develop
$ git merge release/gitflowtest
$ git branch -d release/gitflowtest

pushは自分で

$ git push origin master

これでGithub上のmaster branchにpushされます。
今回は、これでCIがproductionへのdeployをやってくれます。

ref

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8