Git手册 - Git Flow

2021-05-05
git
约 631 字 预计阅读 2 分钟

git flow基本上是协同开发的标准之一,有清晰的简单的分支模型和合作流程,足以应付80%的开发模型,哪怕是个人开发,也推荐使用git flow模式, 衍生的模式还有github flow, gitlab flow等等

1. 介绍

直接上图吧,没啥可介绍的了

git-flow

2. Quick Start

2.1. Initialize

1
git flow init

2.2. Feature

1
git flow feature start rss-feed
1
git flow feature finish rss-feed

2.3. release

1
git flow release start 1.1.5
1
git flow release finish 1.1.5

2.4. hotfix

1
git flow hotfix start missing-link
1
git flow hotfix finish missing-link

3. 原始的git命令实现git flow

3.1. Initialize

gitflow git
git flow init git init
  git commit --allow-empty -m "Initial commit"
  git checkout -b develop master

3.2. Connect to the remote repository

gitflow git
N/A git remote add origin git@github.com:MYACCOUNT/MYREPO

3.3. Features

3.3.1. Create a feature branch

gitflow git
git flow feature start MYFEATURE git checkout -b feature/MYFEATURE develop

3.3.2. Share a feature branch

gitflow git
git flow feature publish MYFEATURE git checkout feature/MYFEATURE
  git push origin feature/MYFEATURE

3.3.3. Get latest for a feature branch

gitflow git
git flow feature pull origin MYFEATURE git checkout feature/MYFEATURE
  git pull --rebase origin feature/MYFEATURE

3.3.4. Finalize a feature branch

gitflow git
git flow feature finish MYFEATURE git checkout develop
git merge --no-ff feature/MYFEATURE
git branch -d feature/MYFEATURE

3.3.5. Push the merged feature branch

gitflow git
N/A git push origin develop
  git push origin :feature/MYFEATURE (if pushed)
3.3.5.1. Releases
3.3.5.1.1. Create a release branch
gitflow git
git flow release start 1.2.0 git checkout -b release/1.2.0 develop
3.3.5.1.2. Share a release branch
gitflow git
git flow release publish 1.2.0 git checkout release/1.2.0
  git push origin release/1.2.0
3.3.5.1.3. Get latest for a release branch
gitflow git
N/A git checkout release/1.2.0
  git pull --rebase origin release/1.2.0

3.3.6. Finalize a release branch

gitflow git
git flow release finish 1.2.0 git checkout master
  git merge --no-ff release/1.2.0
  git tag -a 1.2.0
  git checkout develop
  git merge --no-ff release/1.2.0
  git branch -d release/1.2.0

3.3.7. Push the merged feature branch

gitflow git
N/A git push origin master
  git push origin develop
  git push origin --tags
  git push origin :release/1.2.0 (if pushed)

3.4. Hotfixes

3.4.1. Create a hotfix branch

gitflow git
git flow hotfix start 1.2.1 [commit] git checkout -b hotfix/1.2.1 [commit]

3.4.2. Finalize a hotfix branch

gitflow git
git flow hotfix finish 1.2.1 git checkout master
  git merge --no-ff hotfix/1.2.1
  git tag -a 1.2.1
  git checkout develop
  git merge --no-ff hotfix/1.2.1
  git branch -d hotfix/1.2.1

3.4.3. Push the merged hotfix branch

gitflow git
N/A git push origin master
  git push origin develop
  git push origin --tags
  git push origin :hotfix/1.2.1 (if pushed)

3.5. References

  • http://nvie.com/posts/a-successful-git-branching-model/
  • https://help.github.com/articles/using-pull-requests#shared-repository-model
TAG: git scm
文章作者 : Cocding