Keep your git repository clean and fresh

Tuesday 9 July 2013

If you use GitHub, follow the GitHub flow, and use the pull request system to review code, you must be creating a lot of git branches. From GitHub, you can merge a branch to master and even delete it from origin once merged.

But locally the branch is still here and if you don't pay attention you will accumulate a mess, that is a bunch of merged branches. And I really hate getting 10+ items when running git branch.

Once I receive a confirmation email from GitHub that a pull request I opened has been merged by a fellow coworker, I have this simple routine I run in 4 steps:

$ git m      # Go back to master,
$ git fo     # and fetch origin,
$ git mom    # merge origin/master into local master branch.
$ git sweep  # At last, clean up merged branches and prune.

All this magic happens because of some aliases:

  m = checkout master
  fo = fetch origin
  mom = merge origin master
  sweep = !git branch --merged master | grep -v 'master$' | xargs git branch -d\
          && git remote prune origin

You can review my full .gitconfig on GitHub for more details.

Would you like to learn programming? I am CTO of Le Wagon, a 9-week full-stack web development bootcamp for entrepreneurs, and would be happy to have you on board!

comments powered by Disqus