Simple git workflow with hack and ship
by Laust Rud Jacobsen on December 29, 2010
I use git as my primary version control tool for all internal development, configuration files, and collaborative development. As branches are virtually free with git, it makes a lot of sense to create short-lived feature-branches for each new thing you start working on. This does mean a bit of shuffling back and forth to integrate changes from others in your local work, but this “pull changes and rebase my work” workflow can be greatly eased by these small scripts.
For more than a year I’ve been using two small shell-scripts called hack and ship to manage local feature-branches. Hat-tip goes to ReinH for the original version of these. Notice these shortcuts are only usable when you work on a feature branch based on master, not remote branches in general.
hack pulls down the latest changes from the central origin/master branch, and rebases your local feature-branch on this new master. The end result is all the latest changes are integrated, and you will be able to push your commits without adding an unnecessary merge-commit to the shared history.
#!/bin/sh -x# Exit if any error is encountered:set -o errexit# git name-rev is failCURRENT=`git branch | grep '\*' | awk '{print $2}'`git checkout mastergit pull --rebase origin mastergit checkout ${CURRENT}git rebase master
ship is a quick way to merge your current branch to master, and push the result to the central repository branch called origin/master.
#!/bin/sh -x# Exit if any error is encountered:set -o errexit# git name-rev is failCURRENT=`git branch | grep '\*' | awk '{print $2}'`git checkout mastergit merge ${CURRENT}git push origin mastergit checkout ${CURRENT}Usually when a feature is completed, I run hack, run all code-tests for the project, the run ship. Taken together, the process is automated and looks like this:
hack && rake && ship
where rake runs all relevant tests, and exits with a non-zero error-code. If one or more tests fail, the changes are not shipped (due to the nature of && between the commands), and a fix can be committed before sharing the changes with other developers.
What is your process for managing feature branches in git?
Update:
See also the chop script.
7 comments
git flow is pretty good. https://github.com/nvie/gitflow
by James on January 2, 2011 at 10:14. #
James,
I strongly prefer rebasing my local work before shipping, as I think a linear history is a lot easier to follow. Conventions differ, and I’m glad the merge-centric git-workflow also has some nice tools :)
by Laust Rud on January 2, 2011 at 14:36. #
Great info, will come in handy! Thanks a bunch.
Also “and exists with a non-zero” shouldn’t that be ‘exits’?
by Jaime on January 2, 2011 at 11:15. #
Thank you – fixed.
by Laust Rud on January 2, 2011 at 14:29. #
Nice wrap up for using git.
I guess everyone should start gitting in stead of svn.
by qna on January 2, 2011 at 12:59. #
[...] This post was mentioned on Twitter by Hacker News YC and others. Hacker News YC said: Simple git workflow with hack and ship http://goo.gl/fb/r1KXH [...]
by Tweets that mention Simple git workflow with hack and ship « object.io -- Topsy.com on January 2, 2011 at 21:16. #
[...] steps are part of the local workflow. The hack and ship commands simplify this common scenario…. [full post] Laust Rud Jacobsen object.io toolsgitworkflow 0 0 0 0 [...]
by Simple git workflow with hack and ship on February 4, 2011 at 11:50. #