Skip to content

Instantly share code, notes, and snippets.

@cdaven
Last active December 1, 2016 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdaven/5e379127c47974e63ba8ed416d07be4f to your computer and use it in GitHub Desktop.
Save cdaven/5e379127c47974e63ba8ed416d07be4f to your computer and use it in GitHub Desktop.

git-flow cheat sheet

TL;DR from A successful Git branching model by Vincent Driessen.

Creating a feature branch

When starting work on a new feature, branch off from the develop branch.

$ git checkout -b myfeature develop

Finished features may be merged into the develop branch to definitely add them to the upcoming release:

$ git checkout develop
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop

Creating a release branch

Release branches are created from the develop branch.

$ git checkout -b release-1.2 develop

This new branch may exist there for a while, until the release may be rolled out definitely. During that time, bug fixes may be applied in this branch (rather than on the develop branch).

$ git commit -a -m "Bumped version number to 1.2"

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 is merged into master. Next, that commit on master must be tagged for easy future reference to this historical version. Finally, the changes made on the release branch need to be merged back into develop, so that future releases also contain these bug fixes.

$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2

$ git checkout develop
$ git merge --no-ff release-1.2

Now we are really done and the release branch may be removed, since we don’t need it anymore:

$ git branch -d release-1.2
$ git push origin --delete release-1.2

Creating a hotfix branch

Hotfix branches are created from the master branch.

$ git checkout -b hotfix-1.2.1 master
$ git commit -a -m "Bumped version number to 1.2.1"

Then, fix the bug and commit the fix in one or more separate commits.

$ git commit -m "Fixed severe production problem"

When finished, the bugfix needs to be merged back into master, but also needs to be merged back into develop. This is completely similar to how release branches are finished.

$ git checkout master
$ git merge --no-ff hotfix-1.2.1
$ git tag -a 1.2.1

Next, include the bugfix in develop, too:

$ git checkout develop
$ git merge --no-ff hotfix-1.2.1

The one exception to the rule here is that, when a release branch currently exists, the hotfix changes need to be merged into that release branch, instead of develop.

Finally, remove the temporary branch:

$ git branch -d hotfix-1.2.1

Creating a hotfix branch from existing commits

Instead of cherry-picking from develop to master, create a hotfix branch from master, as described above. Then cherry-pick the commits to that branch, and merge back to master and possibly develop:

$ git checkout -b hotfix-cherries master
$ git cherry-pick -x cf59c452
$ git checkout master
$ git merge --no-ff hotfix-cherries
$ git branch -d hotfix-cherries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment