I am a Web Designer and Developer
working at GitHub

My passion is building beautiful products and working with wonderful people.

Let’s chat

Dead Simple Git Workflow

Recently I have had the privilege to work with a few excellent small agile teams. With each team, they have their own process, which works best for them. And there’s nothing wrong with that, a team should work in it’s most effective way. But I came across a team recently that had a workflow that really impressed me. It is described as an extremely cool Git workflow.

I can’t take credit for coming up with this workflow, but I’m gonna do my best to re-describe it here to be shared. The basis for this post comes from reinh.com’s posts A git workflow for Agile Teams and Hack && Ship. Also this workflow pulls alot from Josh Susser’s post on the story branch pattern.

Let’s start by summarizing Josh’s post. In his post he describes a 7 step process that begins with Pivotal Tracker. The idea being you locate a story on pivotal tracker, like a bug, or feature, or chore. Then you update your working master by pulling from the origin, and create a whole branch for that bug. Once you’ve fixed the bug, commited it to your branch, you then merge your branch with the master and push it all back up to the origin. Then remove the old branch and you’re done.

That’s the basic workflow, but there is alot of automation that can be done. The first is the creation of the branch. This isn’t terribly long command ‘git checkout -b’ but I went ahead and created a shell alias ‘gcb’.

alias gcb='git checkout -b'

Now when creating my branch for working on my bug I type

gcb fix_ie_bug_Story123456

After creating my branch I would work on it normally doing ‘git commits’ when needed. Then when I’m ready comes the cool part. Hack & Ship. Hack is what it’s called when you pull the lastest code from the origin and merge it with your branch. It’s a good idea to do this often, to keep everything up to date. To not have to type and remember the few commands for accomplishing this, I use a shell script.

hack.sh

#!/bin/sh -x
\# hack: Merge the latest changes from the master branch into your current branch
ref=$(git symbolic-ref HEAD 2> /dev/null) || exit 0
CURRENT="${ref#refs/heads/}"
git checkout master
git pull origin master
git checkout ${CURRENT}
git rebase master

When I am coding, I can at anytime type the command hack. And my branch is updated!

Once I’ve finished my bug and I’m ready to send it back to the origin I do one more ‘hack’, make sure it’s all updated. And then I ship. This will checkout the master merge my branch with it, and then push it to the origin. Once again I use a shell script for this.

ship.sh

#!/bin/sh -x
\# Git workflow ship script from: http://reinh.com/blog/2008/08/27/hack-and-and-ship.html
\# git name-rev is fail
ref=$(git symbolic-ref HEAD 2> /dev/null) || exit 0
CURRENT="${ref#refs/heads/}"
git checkout master
git merge ${CURRENT}
git push origin master
git checkout ${CURRENT}

Now I’m done with my bug, and there’s a script for that ‘dwf’. This will move me back to the master, and delete my old branch.

dwf.sh

#!/bin/sh -x
\# dwf, aka "Done With Feature" script: deletes current branch and puts you back on master
ref=$(git symbolic-ref HEAD 2> /dev/null) || exit 0
CURRENT="${ref#refs/heads/}"
git checkout master
git branch -d ${CURRENT}

And we’re ready to repeat the whole process on a new bug/feature/chore.

You can even take this a bit farther, and create an alias for the last three commands ‘hsd’ (hack ship done)

alias hsd="hack && ship && dwf"

Pretty awesome! I’m sure there are hundreds of awesome workflows out there. What do you guys use on your projects?

ad

gitgithubpivotal-trackershell

jonrohan This post was hastily written by Jon Rohan

Text Rotation 8-bit Kill Screen

Related Posts