在 GitHub 上使用 Git-flow

git-flow 是由 Vincent Driessen 這位老兄建立的 Git 分支管理的工作模式,詳細介紹可參考 A successful Git branching model,現在就來看看如何把 git-flow 的開發模式帶進 GitHub 中吧。

在 Ubuntu 中安裝 git-flow
1
$ apt-get install git-flow
初始化一個新的 Repository 並將其命名為 fakerepo
1
2
$ git init fakerepo
$ cd fakerepo
在 Repository 中初始化 git-flow,git-flow 會問你要不要換 Branch 的名稱,這邊都 follow 預設名稱,一直按 Enter 就行了
1
2
3
4
5
6
7
8
9
10
11
$ 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? []
檢查 Branch 是否都有被成功建立出來
1
2
3
4
5
6
7
8
9
10
11
$ git branch
* develop
  master
$ git config -l | grep gitflow
gitflow.branch.master=master
gitflow.branch.develop=develop
gitflow.prefix.feature=feature/
gitflow.prefix.release=release/
gitflow.prefix.hotfix=hotfix/
gitflow.prefix.support=support/
gitflow.prefix.versiontag=
把剛建好的 Repository 送上 GitHub
1
2
3
4
5
6
7
8
9
$ git remote add origin https://github.com/shyuan/fakerepo.git
$ git push --set-upstream origin develop
To https://github.com/shyuan/fakerepo.git
 * [new branch]      develop -> develop
Branch develop set up to track remote branch develop from origin.
$ git push --set-upstream origin master
To https://github.com/shyuan/fakerepo.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
檢查 Branch
1
2
3
4
5
6
$ git branch
* develop
  master
$ git branch -r
  origin/develop
  origin/master
其他使用者的操作步驟
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ git clone https://github.com/shyuan/fakerepo.git
$ cd fakerepo
$ git branch
* master
$ git branch -r
origin/HEAD -> origin/master
origin/develop
origin/master
$ 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]

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