Work on multiple branches with Git workdir

27 Oct 2013

Sometimes I find the need to work on multiple branches in the same repository at once. This can be caused by many different scenarios; waiting for tests to finish, running two versions of an application at the same time etc. In short, anywhere where a regular git stash/branch workflow falls short. I also wanted a solution where I didn’t have to manage multiple .git folders.

Git workdir to the rescue

I found a useful script in git-contrib called git-workdir which enables having the same repository in multiple states. Since it’s just a bash script, there are many ways to install it, I’ve done it like this:

cd ~/Code/libs/
git clone

# add an alias for the workdir script
alias git-new-workdir='~/Code/libs/git/contrib/workdir/git-new-workdir'

With the script installed, you can now create a ‘clone’ of your checkout like this:

# usage: git-new-workdir <checkout-folder> <clone-folder>

git-new-workdir my-app my-app-CLONE

The script achieves having multiple states on the same checkout by using some arcane symlinking which I will not go into detail with here. For more information about the script, have a look at the source.


Having multiple states on the same checkout can easily create problems if you’re not paying attention. I recommend strong coffee and/or sufficient sleep beforehand.