[Git] An efficient GIT workflow for mid/long term projects

简介:

reference : http://fle.github.io/an-efficient-git-workflow-for-midlong-term-projects.html

Our full-web  project has been going on for nearly two years and is running in production for over 18 months. I think it's my first project without any headache about our codebase and VCS management. So, I'll present our GIT workflow which has proven to be very effective for now.

Context

  • Several developers
  • Several staging/pre-production servers, several (non-synchronous) production servers
  • Monthly releases (more or less) with delivery on staging, then on production servers
  • On servers, basecode is directly pulled from the GIT repository with fabric

Rules

To handle this, we have set some simple rules:

  1. One (and only one) maintainer, who manage GIT repository and releases
  2. Never commit directly on master
  3. Never rebase master on any branch
  4. Do not get out of planned workflow

Workflow

Master branch

Our branch master is the common trunk and simply contains all the codebase of the next release. Since we don't work directly on it, it evolves mainly with merges.

Workflow GIT 1

Development branches

When a developer starts a new feature or a bugfix, he creates a new branch from master HEAD

1
2
3
$ (master) git checkout -b featureA
$ (featureA) git commit -a -m  "featureA part 1"
$ (featureA) git commit -a -m  "featureA part 2"
Workflow GIT 2

He follows branch master evolution and regularly ensures his code still works, by rebasing his branchfeatureA on branch master.

1
$ (featureA) git rebase master

 

When his developments are done (commits fa1 / fa2 in schema below), he does a last rebase. Thanks to this:

  • he ensures that the maintainer will be able to merge easily (maintainer should not need to read code deeply and search why there are conflicts)
  • if tests pass on development branch after rebase, they should pass on master after merge, so we ensure that branch ``master`` is always working well

Possibly, it will be the good time to clean the development branch to let it neat just when it is finished.

Workflow GIT 3

The maintainer can now merge this branch in master peacefully, without big conflict troubles. As the maintainer, I like to use no-ff option to force a merge commit, so history can stay really readable (we easily see where the branch has started and where it has been merged).

1
$ (master) git merge --no-ff featureA

 Workflow GIT 4

Now that the branch has been merged, the developer should remove his development branch.

1
2
$ (master) git branch -d featureA
$ (master) git push origin :featureA

 

Stable branches

When we prepare a release, we update CHANGELOG (with our workflow, a git log --oneline should be quite clear to do that) and tag the branch master (optional), then we start a stable branch.

1
2
3
$ (master) git tag 1.0
$ (master) git checkout -b stable1.0
$ (stable1.0) git push origin stable1.0

 

This branch is deployed on different servers.

While development goes on, we possibly have to do some hotfixes (for example: commit hf1 in schema below), that must be sent in production quickly. These hotfixes are done directly on concerned stable branch.

Workflow GIT 5

Regularly, the maintainer merges stable branch in master to bring back these commits. This action is particularly important before the next release.

 
1
$ (master) git merge --no-ff stable1.0

 

We found this method really useful because:

  • each stable branch has its own life and doesn't take care of branch master evolution, so we can hotfix stable branche freely and without stress
  • we ensure that no hotfix commit has been lost before next release (avoid regressions)

A complete history example

Workflow GIT 6

Conclusion

Of course, there are several GIT workflows which can be very efficient, but we found many advantages in working with this method, and no real issue:

  • Branch master is always clean and working well
  • Developers don't care about GIT whole workflow
  • We can fix stable branch without asking ourselves what happened on master since last release
  • We ensure that each stable release contains new features and possible fixes
  • Always working with branches and using``-no-ff``option make history really clear !
  • This workflow is scalable (number of developers or branches doesn't really matter)

 

 

 

分类:  Git
本文转自demoblog博客园博客,原文链接http://www.cnblogs.com/0616--ataozhijia/p/8034173.html如需转载请自行联系原作者

demoblog
相关文章
|
开发工具 git
Git Workflow简介
1. Git WorkFlow介绍 Git Flow是构建在Git之上的一个组织软件开发活动的模型,是在Git之上构建的一项软件开发最佳实践。Git Flow是一套使用Git进行源代码管理时的一套行为规范和简化部分Git操作的工具。
1610 0
|
网络安全 开发工具 git
Git workflow
Git workflow 大神镇楼: 这人不用说,应该都认识,他基本干了两件事,一个是Linux,一个就是git。每一件事,都在IT史上创建了一个巨大的Tag。 Git是什么 Git能干什么? Git用来做版本控制,这就好比当初在小日本的公司,每次修改文件,都需要在文件第一页新增修改履历,详细记录修改内容,如果多人同时操作,你可以想象下维护的成本有多高。
1030 0
|
2月前
|
开发工具 git
git 常用命令
这些只是 Git 命令的一部分,Git 还有许多其他命令和选项,可根据具体需求进行深入学习和使用。熟练掌握这些命令能够帮助你更高效地管理代码版本和协作开发。
|
5月前
|
存储 开发工具 git
|
29天前
|
机器学习/深度学习 Shell 网络安全
【Git】Git 命令参考手册
Git 命令参考手册的扩展部分,包含了从基础操作到高级功能的全面讲解。
33 3
|
5月前
|
开发工具 git
【GIT 第二篇章】GIT常用命令
Git常用命令涵盖初始化、状态管理、提交、分支处理、远程操作等关键流程。`git init`启动本地仓库,`git clone`下载远程仓库。通过`git status`和`git diff`检查工作状态与差异。利用`git add`暂存文件,`git commit`保存更改。借助`git branch`、`git checkout`、`git merge`和`git rebase`管理分支。使用`git fetch`、`git pull`和`git push`同步远程仓库。通过`git reset`、`git revert`和`git checkout`实现版本回退。
77 0
|
2月前
|
缓存 Java Shell
[Git]入门及其常用命令
本文介绍了 Git 的基本概念和常用命令,包括配置、分支管理、日志查看、版本回退等。特别讲解了如何部分拉取代码、暂存代码、删除日志等特殊需求的操作。通过实例和图解,帮助读者更好地理解和使用 Git。文章强调了 Git 的细节和注意事项,适合初学者和有一定基础的开发者参考。
57 1
[Git]入门及其常用命令
|
3月前
|
开发工具 git
git学习四:常用命令总结,包括创建基本命令,分支操作,合并命令,压缩命令,回溯历史命令,拉取命令
这篇文章是关于Git常用命令的总结,包括初始化配置、基本提交、分支操作、合并、压缩历史、推送和拉取远程仓库等操作的详细说明。
148 1
git学习四:常用命令总结,包括创建基本命令,分支操作,合并命令,压缩命令,回溯历史命令,拉取命令
|
2月前
|
开发工具 git 开发者