Years ago I read Streamed Lines: Branching Patterns for Parallel Software Development, and many of the thoughts have stayed me. Think of it as a catalogue of Design Patterns for version control workflows. There are so many ways to efficiently use branches to both collaborate and isolate work. Lively discussions can be had on how to best organize a repository, and having a great overview of the options makes for more informed discussions.
I have previously described how I’ve been using small hack && ship commands to simplify and streamline my personal git workflow. Recently I’ve switched to using the Git Flow setup as my branching and release workflow.
Setting up git-flow
The git-flow project also has instructions for installation on Linux and Windows.
Installing git-flow adds a few helpful commands to the git environment for creating and managing branches for features and releases. A fresh git repository is born with a
masterbranch. In the default git-flow setup, this is where the current production release lives. Furthermore, a branch called
developis created, this is where development takes place. Note that git-flow is just a series of shortcuts to having a development branch and a production branch with sensible ways of shuttling changes back and forth. After installing the git-flow package, configure your local repository for git-flow use with:
You can most likely accept the defaults by pressing enter at each question - this also makes it easier for others to initialize git-flow in their working copy, as all are using the same defaults. The only change from running the
initcommand is two
[gitflow]sections in your
.git/configfile looking like this:
It’s no more magic than that. Consult the built-in help with:
If you’ve got the
bash-completionpackage installed, you can use tab-completion for git-flow commands and arguments. Highly recommended.
Working on a feature
Start work on a feature - say feature 77 from your issue-tracker:
This creates a new regular local git branch called
feature/77-speedup-yak-shavingbased on the current
developand places you on it. Want to share your work in progress with others? Use:
This pushes the branch, and sets up your local branch to track the remote branch in one easy step. The regular
git pull --rebasework as you would expect here. There is nothing special about branches created by git-flow, they are just conveniently named and managed.
All done with a feature? Rebase your feature on the current
developbranch, then merge it in:
With these two steps, you end up on
developwith your feature merged in. Run your test-suite, and push to a central repository as appropriate.
Releasing to production version and hotfixes
Production releases are handled quite nicely in git-flow:
This creates a new branch called
release/2011_year_of_the_yak, based on the current
developbranch. Here you can fix any HISTORY or VERSION file, commit, and the finish up the release with:
By finishing the release, you now get a tag called
2011_year_of_the_yak, and the temporary release-branch is removed. You end up back at the
A hotfix is simply a feature branch which is based on the latest production release, and which is automatically merged to both
master. Extremely handy.
Rebase considered harmful?
Some developers prefer to only ever merge, but I’m a big fan of rebasing local work before publishing. I’ll leave you with this:
If you treat rebasing as a way to clean up and work with commits before you push them, and if you only rebase commits that have never been available publicly, then you’ll be fine. If you rebase commits that have already been pushed publicly, and people may have based work on those commits, then you may be in for some frustrating trouble.
From Pro Git, chapter 3
There are many ways to backup a git repository and shuttle sets of changes around. If you just want an offline copy for safe-keeping, this method is very simple and convenient:
This creates a file
blog-dump.bundlewith the full history for
master, including all parent commits. You now have a single file, which can effectively be mailed, downloaded via SCP or FTP, or simply moved to Dropbox (affiliate link) for safe keeping, or otherwise shared with others.
Single files are easy to archive and backup.
Thawing a bundle
When you want to restore from such a bundle backup, you simply clone from it. The steps include creating a new repository, and then pulling from the bundle, like you would a remote repository:
Your repository now holds all commits that were stored in the bundle. For more usage-scenarios see the official git bundle help or just type:
subscribe via RSS