[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.

Development branches

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

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

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

$ (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.

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).

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

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

$ (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.

$ (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.

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

 
$ (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

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)
时间: 2024-11-05 20:49:40

[Git] An efficient GIT workflow for mid/long term projects的相关文章

git项目实战常用workflow和命令

一个从无到有的项目大体经历-创建项目目录,创建repo,配置过滤集,配置git user,导入已有基础代码入库,将库放到central去,建立分支,修改代码,checkin代码,分支上 测试验证代码,merge稳定代码回主线,打tag,push到中央库分享 mkdir app   cd app   git init   cd .git   vi description   cd info   sudo vi exclude cd ../../ (app目录)   git add --all   

[Git] MAC上Git初探

1.基本设置,包括用户名.邮箱.编辑工具.查看设置.帮助等 $ git config --global user.name "John Doe" $ git config --global user.email [email protected] $ git config --global core.editor vim $ git config --list $ git help xxx(如config) 2.创建第一个Git库 $ git init 本地git维护由三棵树组成,Wo

git pull 与git fetch的区别

从百度上看到很多关于git fetch 和 git  pull 的不同 实践一下: 从github上新建一个项目try,copy到本地. 在github网站里修改readme.txt文件,新增加一句[alter readme] 在本地仓库的readme.txt也新增加一句,[add some thing] 现在想把本地代码提交到github上,是不能提交的.会出现错误提示!!! 应该先从远程仓库中把代码下载下来 (1)用git pull会怎么样呢? git pull origin master

Git fetch和git pull的区别

2013-03-04 10:58 65080人阅读 评论(4) 收藏 举报 Git中从远程的分支获取最新的版本到本地有这样2个命令: 1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge Git fetch origin mastergit log -p master..origin/mastergit merge origin/master 以上命令的含义: 首先从远程的origin的master主分支下载最新的版本到origin/master分支上 然后比较本地的m

git fetch 、git pull 与 git pull --rebase

1. git fetch 与 git pull 都是从远程拉取代码到本地,git fetch只是拉取到本地,git pull不仅拉取到本地还merge到本地分支中.所以git pull是git fetch与git merge的集合体.  2. git pull 与 git pull --rebase git pull的默认行为是git fetch + git merge,  git pull --rebase则是git fetch + git rebase. 从目的来说,两者没差别,运行之后,

代码回滚:git reset、git checkout和git revert区别和联系

git reset.git checkout和git revert是你的Git工具箱中最有用的一些命令.它们都用来撤销代码仓库中的某些更改,而前两个命令不仅可以作用于提交,还可以作用于特定文件. 因为它们非常相似,所以我们经常会搞混,不知道什么场景下该用哪个命令.在这篇文章中,我们会比较git reset.git checkout和git revert最常见的用法.希望你在看完后能游刃有余地使用这些命令来管理你的仓库. Git仓库有三个主要组成——工作目录,缓存区和提交历史.这张图有助于理解每个

Git学习 -- 自定义Git

忽略特殊文件 在工作区创建.gitignore文件,编写内容 # Windows: Thumbs.db ehthumbs.db Desktop.ini # Python: 忽略Python编译产生的.pyc..pyo.dist等文件或目录 *.py[cod] *.so *.egg *.egg-info dist build # My configurations: db.ini deploy_key_rsa 然后add和commit该文件 此后当工作区出现.gitignore中类型文件时,git

Git手册 - 安装Git

一.Git之历史 Git是Linus(大牛,不需要介绍吧)为了方便管理Linux系统的源代码而开发的一款分布式版本管理系统. 二.理解Git的分布式特点 Git的分布式是指基于git的版本控制系统没有"中央服务器",任意两两之间可以相互推送,并且每个开发者的电脑上都是一个完整的版本库,可以任意的回退. 但现实情况是:为了方便源代码的管理,通常一个项目会设定一个名义上的"中央代码库". 三.Git安装 1)Windows 下载地址:https://git-scm.co

Git学习笔记——Git安装

Git是目前世界上最先进的分布式版本控制系统(没有之一). 在Linux上安装Git 首先,你可以试着输入git,看看系统有没有安装Git: $ git The program 'git' is currently not installed. You can install it by typing: sudo apt-get install git 像上面的命令,有很多Linux会友好地告诉你Git没有安装,还会告诉你如何安装Git. 如果你碰巧用Debian或Ubuntu Linux,通过