Shamelessly plagiarized from http://nvie.com/posts/a-successful-git-branching-model/ (but adapted to the model I like to use).
Exactly what to develop in which branches is a puzzling problem, especially for developers new to branching, large teams, and developers with regular releases.
In this post I present the development model that I try to introduce for all of my projects (both at work and private). I’ve been meaning to write about it for a while now, but I’ve never really found the time to do so thoroughly, until now, but only because I shamelessly plagiarize so much. I also won’t talk about any of the projects’ details, merely about the branching strategy and release management.

It focuses around Git as the tool for the versioning of all of our source code.
Why git?
I’m sure any code repository system that properly supports branching will be fine. I’m used to git and I haven’t worked on a project that uses mercurial or darcs, but they’re probably fine as well. RCS/SCCS/CVS/SVN do not do branching nicely, if at all. A decentralized system like git/mercurial/darcs is not necessary, but you should be familiar with how to get others’ changes for whichever tool you use.
Enough about the tools, let’s head onto the development model. The model that I’m going to present here is essentially no more than a set of procedures that every team member has to follow in order to come to a managed software development process.
The main branch

At the core, the development model is greatly inspired by existing models out there. The central repository (origin) holds one main branch with an infinite lifetime, master.
The master branch at origin should be familiar to every Git user.
We consider origin/master to be the main branch where the source code of HEAD always reflects a state with the latest delivered development changes for the next release. Some would call this the “integration branch”. This is where any automatic nightly builds are built from.
When the source code in the master branch reaches a stable point and is ready to be released, all of the changes should be branched off somehow and then tagged with a release number. How this is done in detail will be discussed further on.
Therefore, each time when changes are merged back into master, this will go into the next minor release.
Supporting branches
Next to the main branch master, our development model uses a variety of supporting branches to aid parallel development between team members, ease tracking of features, prepare for production releases and to assist in quickly fixing live production problems. Unlike the main branches, these branches always have a limited life time, since they will be removed eventually.
The different types of branches we may use are:
- Feature branches
- Release branches
Each of these branches have a specific purpose and are bound to strict rules as to which branches may be their originating branch and which branches must be their merge targets. We will walk through them in a minute.
By no means are these branches “special” from a technical perspective. The branch types are categorized by how we use them. They are of course plain old Git branches.
Feature branches

May branch off from: origin/master
Must merge back into: origin/master
Branch naming convention: anything except master or release-*
Feature branches (or sometimes called topic branches) are used to develop new features for the upcoming or a distant future release. When starting development of a feature, the target release in which this feature will be incorporated may well be unknown at that point. The essence of a feature branch is that it exists as long as the feature is in development, but will eventually be merged back into master (to definitely add the new feature to the upcoming release) or discarded (in case of a disappointing experiment).
Creating a feature branch
When starting work on a new feature, branch off from the master branch.
$ git checkout -b myfeature origin/master
Switched to a new branch "myfeature"
Incorporating a finished feature onto master
Finished features may be merged into the master branch to definitely add them to the upcoming release:
$ git merge --no-ff origin/master
Updating ea1b82a..05e9557 (Summary of changes)
$ git push origin myfeature:master :myfeature
$ git branch -d myfeature
Deleted branch myfeature (was 05e9557).
The --no-ff flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature. Compare:

In the latter case, it is impossible to see from the Git history which of the commit objects together have implemented a feature—you would have to manually read all the log messages. Identifying a whole feature (i.e. a group of commits), is a true headache in the latter situation, whereas it is easier to do if the --no-ff flag was used.
Yes, it will create a few more (empty) commit objects, but the gain is much bigger that that cost.
You can make --no-ff the default behaviour of git merge by running git config merge.ff false
The fancy push command pushes myfeature (which has all the commits from origin/master and myfeature) to origin/master and also deletes origin/myfeature, if it existed.
Release branches
May branch off from: master
Must merge back into: master
Branch naming convention: release-*
Release branches support preparation of a new production release. They allow for last-minute dotting of i’s and crossing t’s. Furthermore, they allow for minor bug fixes and supporting multiple releases simultaneously. By doing all of this work on a release branch, the master branch is cleared to receive features for the next big release.
The key moment to branch off a new release branch from master is when master (almost) reflects the desired state of the new release. At least all features that are targeted for the release-to-be-built must be merged in to master at this point in time. All features targeted at future releases must not—they must wait until after the release branch is branched off.
It is exactly at the start of a release branch that the upcoming release gets assigned a version number—not any earlier. Up until that moment, the master branch reflected changes for the “next release”, but it is unclear whether that “next release” will eventually become 0.3 or 1.0, until the release branch is started. That decision is made on the start of the release branch and is carried out by the project’s rules on version number bumping.
Creating a release branch
Release branches are created from the master branch. For example, say version 1.1 is the current production release and we have a big release coming up. The state of master is ready for the “next release” and we have decided that this will become version 1.2 (rather than 2.0). So we branch off and give the release branch a name reflecting the new version number:
$ git checkout -b release-1.2 master
Switched to a new branch "release-1.2"
$ ./bump-version.sh 1.2.0
Files modified successfully, version bumped to 1.2.0.
$ git commit -a -m "Bumped version number to 1.2.0"
[release-1.2 74d9424] Bumped version number to 1.2.0
1 files changed, 1 insertions(+), 1 deletions(-)
After creating a new branch and switching to it, we bump the version number. Here, bump-version.sh is a fictional shell script that changes some files in the working copy to reflect the new version. (This can of course be a manual change—the point being that some files change.) Then, the bumped version number is committed.
This new branch may exist there for a while, until the release is no longer supported. During that time, bug fixes may be applied in this branch (rather than on the master branch). You could repeatedly bump the version number for bug fix releases (1.2.1, 1.2.2, etc.) Adding large new features here is strictly prohibited. They must be merged into master, and therefore, wait for the next big release.
Rolling out a release branch
Each time we want to roll-out, we tag the code the release was built from. We tend to be very strict at this, so that theoretically, we could use a Git hook script to automatically build and roll-out our software to our production servers everytime there was a tag on release-*.
When the state of the release branch is ready to become a real release, some actions need to be carried out. First, the release branch must be tagged for easy future reference to this historical version. Secondly, the changes made on the release branch need to be merged into the branches of other supported releases and master, so that future releases also contain these bug fixes.
The first step in Git:
$ git tag -a 1.2.0
The release is now done, and tagged for future reference.
You might as well want to use the -s or -u <key> flags to sign your tag cryptographically.
To keep the changes made in the release branch, we need to merge those back into master, though. In Git:
$ git checkout master
Branch master set up to track remote branch master from origin.
Switched to a new branch 'master'
$ git merge --no-ff release-1.2
Merge made by the 'recursive' strategy.
(Summary of changes)
$ git push origin master release-1.2
This step may well lead to a merge conflict (probably even, since we have changed the version number). If so, fix it and commit. Alternatively, you can cherry-pick the commits you want. This may be more painful, but won’t put unwanted version-bump commits in the other release branches:
$ git checkout master
Branch master set up to track remote branch master from origin.
Switched to a new branch ‘master’
$ git cherry-pick release-1.2.0..release-1.2.1^
$ git push origin master release-1.2
In this example, we cherry-picked everything after the tag release-1.2.0 and before the tag release-1.2.1. Presumably the unwanted commits are the tagged ones.
Now we are really done and the local copy of the master branch may be removed, since we don’t need it anymore:
$ git checkout release-1.2
$ git branch -d master
Deleted branch master (was ff452fe).
Hotfixes

May tag in: release-*
Must merge/cherry-pick into: release-* and master
Tag naming convention: release-x.y.z
Hotfixes are done in release branches as they also are meant to prepare for a new production release, albeit unplanned. They arise from the necessity to act immediately upon an undesired state of a live production version. When a critical bug in a production version must be resolved immediately, a hotfix commit may be tagged in the corresponding release branch that marks the production version.
The essence is that work of team members (on the master branch) can continue, while another person is preparing a quick production fix.
Creating the hotfix commit
Hotfixes are created from the release-* branch. For example, say version 1.2.0 is the current production release running live and causing troubles due to a severe bug. But changes on master are yet unstable. We may then check out the problematic branch and start fixing the problem:
$ git checkout -b release-1.2
Branch release-1.2 set up to track remote branch release-1.2 from origin.
Switched to a new branch 'release-1.2'
Then, fix the bug and commit the fix in one or more separate commits.
$ git commit -m "Fixed severe production problem"
[release-1.2 abbe5d6] Fixed severe production problem
5 files changed, 32 insertions(+), 17 deletions(-)
Rolling out a hotfix
When finished, the bugfix needs to be merged back into master, but also needs to be merged back into the other release branches, in order to safeguard that the bugfix is included in all supported releases as well. This is completely similar to how release branches are rolled out.
First, tag the release.
$ ./bump-version.sh 1.2.1
Files modified successfully, version bumped to 1.2.1.
$ git commit -a -m "Bumped version number to 1.2.1"
[release-1.2 41e61bb] Bumped version number to 1.2.1
1 files changed, 1 insertions(+), 1 deletions(-)
$ git tag -a 1.2.1
Don’t forget to bump the version number before tagging!
You might as well want to use the -s or -u <key> flags to sign your tag cryptographically.
Next, include the bugfix in master, too:
$ git checkout master
Switched to branch 'master'
$ git merge --no-ff release-1.2
Merge made by the 'recursive' strategy.
(Summary of changes)
The one exception to the rule here is that, when another release branch is currently supported, the hotfix changes need to be merged into that release branch, in addition to master. Back-merging the bugfix into the master branch will eventually result in the bugfix being merged into future release branches too, when the releases are ready, but doesn’t help for past releases.
Summary
While there is nothing really shocking new to this branching model, the “big picture” figure that this post began can turn out to be tremendously useful in your projects. It forms an elegant mental model that is easy to comprehend and allows team members to develop a shared understanding of the branching and releasing processes.
A high-quality PDF version of the figure is provided here. Go ahead and hang it on the wall for quick reference at any time.
And for anyone who wants it: here’s the gitflow-model.src.svgz of the main diagram image (Inkscape).

Git-branching-model.pdf
Feel free to add your comments!
If you want to get in touch, I’m @jayenashar on Twitter.