SourceTree上でGit Flowを動かしてみる 



SourceTreeを使って Git Flowを動かしてみて、Git Flowの開発フローを整理してみました。


SourceTreeでGit Flowを実施するには、基本的には何かしようとしたら右上にある Git FlowのアイコンをクリックすればOKです。そのときに応じた、Git Flowのコマンドを実行することができます。

![00UI.png](https://qiita-image-store.s3.amazonaws.com/0/73777/58ed5762-ae16-1990-367c-9e139fbfbfe0.png "00UI.png")


## 初回のみ
### Git Flow開始時

![01Git-Flow開始時.png](https://qiita-image-store.s3.amazonaws.com/0/73777/b969aff1-6783-fec9-44c0-4bc1b989ad5c.png "01Git-Flow開始時.png")


```bash
git init -d 
Using default branch names.

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? [] 
Completed successfully
``` 

## チケット対応開始時
### 新規フィーチャー dev_50 の開始

![02新規Feature dev_50の開始01.png](https://qiita-image-store.s3.amazonaws.com/0/73777/4a67c424-7a65-8b25-424b-b5559a767697.png "02新規Feature dev_50の開始01.png")

![02新規Feature dev_50の開始02.png](https://qiita-image-store.s3.amazonaws.com/0/73777/2e400740-1afc-3226-50e5-eccca1eb7495.png "02新規Feature dev_50の開始02.png")



```bash
git feature start dev_50 
Switched to a new branch 'feature/dev_50'

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

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

     git flow feature finish dev_50

Completed successfully
``` 


### 開発！

開発します。仮想的に下記の二つをコミットして、リモートにプッシュしておきます。

下記は実際に自分で実行したコマンド。

```bash
$ git commit --allow-empty -m '#50 start.'
[feature/dev_50 ec9378f] #50 start.
$ git commit --allow-empty -m '#50 end.'
[feature/dev_50 9ef6661] #50 end.
```

```bash
$ git push origin feature/dev_50
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 280 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/masatomix/git-flow-sample.git
 * [new branch]      feature/dev_50 -> feature/dev_50
$
``` 


###現在のブランチ(フィーチャー)の終了

![03現在のブランチの終了01.png](https://qiita-image-store.s3.amazonaws.com/0/73777/ba62a98f-cf6c-ae5e-feb4-dc4fde5066de.png "03現在のブランチの終了01.png")

![03現在のブランチの終了02.png](https://qiita-image-store.s3.amazonaws.com/0/73777/e99caeca-86ac-d2f8-2672-19769de960aa.png "03現在のブランチの終了02.png")



```bash
git feature finish -k dev_50          ← -k はローカルブランチを残す設定(削除を選んだら、-kはつかなかった)
Switched to branch 'develop'
Your branch is up-to-date with 'origin/develop'.
Already up-to-date!
Merge made by the 'recursive' strategy.

Summary of actions:
- The feature branch 'feature/dev_50' was merged into 'develop'
- Feature branch 'feature/dev_50' is still available
- You are now on branch 'develop'

Completed successfully
``` 



##リリース開始時
各種チケット対応はいったん停止し、リリース準備作業にはいります。

### 新規リリースの開始

↓間違えないように「新規リリースを開始」を選択
![04新規リリースの開始01.png](https://qiita-image-store.s3.amazonaws.com/0/73777/64b49fe7-8760-2403-c544-49eb659801bf.png "04新規リリースの開始01.png")

![04新規リリースの開始02.png](https://qiita-image-store.s3.amazonaws.com/0/73777/e7b3b11f-6310-1f96-e5e5-606f28976c92.png "04新規リリースの開始02.png")


```bash
git release start 0.0.2 
Branches 'develop' and 'origin/develop' have diverged.
And local branch 'develop' is ahead of 'origin/develop'.
Switched to a new branch 'release/0.0.2'

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

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

     git flow release finish '0.0.2'

 Completed successfully
``` 

###リリース準備作業！

仮想的なリリース準備作業としてこんなコミットとプッシュを。
下記は実際に自分で実行したコマンド。

```bash
$ git commit --allow-empty -m 'release 0.0.2 start.'
[release/0.0.2 5a65a48] release 0.0.2 start.
$ git commit --allow-empty -m 'release 0.0.2 end.'
[release/0.0.2 0759703] release 0.0.2 end.
```

```bash
$ git push origin release/0.0.2
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 440 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
To https://github.com/masatomix/git-flow-sample.git
 * [new branch]      release/0.0.2 -> release/0.0.2
$
``` 

###リリースの完了(UI上は、ブランチの終了)

![05リリースの完了01.png](https://qiita-image-store.s3.amazonaws.com/0/73777/75e04b94-aa85-a3c9-4e89-b5acc213444b.png "05リリースの完了01.png")

![05リリースの完了02.png](https://qiita-image-store.s3.amazonaws.com/0/73777/0af8f883-62ad-dbaf-ffc0-3951a1d4e74e.png "05リリースの完了02.png")



```bash
git release finish -k -f /var/folders/fp/ph0q_b6s64v9pmpbn8x547400000gp/T/SourceTreeTemp.nX6rDe 0.0.2 
Branches 'develop' and 'origin/develop' have diverged.
And local branch 'develop' is ahead of 'origin/develop'.
Switched to branch 'master'
Switched to branch 'develop'
Your branch is up-to-date with 'origin/master'.
Already up-to-date!
Merge made by the 'recursive' strategy.
Your branch is ahead of 'origin/develop' by 3 commits.
  (use "git push" to publish your local commits)
Already up-to-date!
Merge made by the 'recursive' strategy.

Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch has been merged into 'master'
- The release was tagged '0.0.2'
- Release branch has been back-merged into 'develop'
- Release branch 'release/0.0.2' is still available

Completed successfully
```

コミットグラフは以下のようになりました。

![06graph01.png](https://qiita-image-store.s3.amazonaws.com/0/73777/dcee86f2-678e-b14d-92f9-f6310035eecd.png "06graph01.png")


流れをまとめると、以下の通り。

- developからfeature/dev_50 がブランチされて、対応が完了したらdevelopへマージコミット。
- また、develop からリリース用の release/0.0.2 がブランチされ、そこでリリース準備作業が行われます。
- リリースブランチでの作業が develop と master へマージコミットされ、最後にそのマスターの状態(というかコミット)にタグ0.0.2が打たれます。



##ローカルの変更をGitHubへプッシュ

最後に develop master ブランチとタグ 0.0.2 をリモートへプッシュして、作業完了です。
下記は実際に自分で実行したコマンド。

```bash
$ git push origin develop
Counting objects: 1, done.
Writing objects: 100% (1/1), 242 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/masatomix/git-flow-sample.git
   aa3dca8..f749970  develop -> develop
```

```bash
$ git push origin master
Counting objects: 1, done.
Writing objects: 100% (1/1), 234 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/masatomix/git-flow-sample.git
   aa3dca8..63ad35a  master -> master
$
```

```bash
$ git tag
0.0.2
```


```bash
$ git push origin 0.0.2
Counting objects: 1, done.
Writing objects: 100% (1/1), 171 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/masatomix/git-flow-sample.git
 * [new tag]         0.0.2 -> 0.0.2
$
``` 

![06graph02.png](https://qiita-image-store.s3.amazonaws.com/0/73777/50057133-d392-3319-239d-f66c5340aca4.png "06graph02.png")


 
以上お疲れ様でした。