LoginSignup
59
71

More than 5 years have passed since last update.

既存リポジトリにgit-flowを導入

Last updated at Posted at 2014-06-07

1.git-flowインストール

Linuxなら

yum install git-flow

Linux(Ubunts)の場合:

bash
$ sudo apt-get install git-flow

Macなら

brew install git-flow

とかする。


2.事前にブランチ「develop」を作成しておく

$ git checkout master
Already on 'master'
Your branch is up-to-date with 'origin/master'.
$ git branch develop
git checkout master

で、現在のブランチを「master」に合わせて

git branch develop

で、ブランチ「develop」を作成します。


3.既存リポジトリにgit-flowを導入

$ git flow init

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

Which branch should be used for integration of the "next release"?
   - develop
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? []
$

なんか色々聞かれますが、全部デフォルトでいいと思うので、Enterを押しておきます。


4.GitHubと連動

GitHubのIssueを作成し、そのIssue番号ごとにブランチ「feature/{issue_id}」を作成していけば、GitHubと連動することが出来ます。

なので、適当にIssueを作って
(ここではIssue番号1のIssueを作成したものとします)

git flow feature start 1

とかすると、ブランチ「feature/1」が作成され、これをコミット・プッシュすることにより、該当するIssue番号のfeatureブランチを作成することが出来ます。

ただし、 実際はcommitコメントが連動するだけのようなので(ちゃんとチェックしてませんが、動きを見ると多分そう)、コミットする際に

message #{issue_id}

という形式でコメントし、コミットしていきましょう。

例えば、Issue番号が1の場合は

git commit -m "修正内容 #1"

等とします。

そうすると下図のように、GitHub上のIssueにコミットごとの差分がリンクされるので、ブラウザ上でコードレビューしたり、変更点を確認したりすることが出来ます。

xx.png


※ただし、ブランチ「feature/xx」をブランチ「develop」にマージするようにプルリクエストを使って他の人に依頼する場合には、Issue番号とブランチ「feature/xx」の名前はIssue番号と合わせて作っておくのがいいでしょう。
理由としては
・「feature」ブランチに分けておかないとプルリクエストが出来ない
・番号を合わせておくと、このIssueに対するプルリクエストだよっていうのが分かる
があります。


5.developブランチにマージ

featureブランチを終了して、変更点をdevelopブランチに反映するには

git flow feature finish {issue_id}

というコマンドを使います。

Issue番号が1とすると

git flow feature finish 1

というコマンドになります。

これをすると、ブランチ「feature/1」での変更点がブランチ「develop」にマージされます。


6.developブランチをプッシュする

ブランチ「develop」にマージされたので、プッシュします。

git push origin develop

でブランチ「develop」の内容をプッシュすることが出来ます。


7.現在のブランチ確認

現在のブランチがどこにセットされているかは

git status

git branch

などのコマンドで知ることが出来ます。

59
71
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
59
71