Git - Store branches in separate local directories

Branches are first class citizens in Git. They are not "emulated" as branches like in older VCS such SVN, CVS, etc.

If you really need three different directories, because you want to have three distinct development environment, make 3 clones:

  • one in a directory called master
  • one in a directory called imp_1
  • one in a directory called imp_2

But to really understand branches, you can read "Pros and cons of different branching models in DVCS".


Or, since Git 2.5 (July 2015, 4 years after the OP's question), as I detailed in Multiple working directories with Git?, use git worktree.

That will be one clone, multiple folders (one per branch).
With Git 2.7+, you can then list those folders:

$ git worktree list
/path/to/bare-source            (bare)
/path/to/linked-worktree        abcd1234 [master]
/path/to/other-linked-worktree  1234abc  (detached HEAD)

You can do this using git worktree that was introduced in Git 2.5, circa July 2015.

git clone -b master <repo> master
cd master

# checking out implementation_1 in ../imp_1
git worktree add ../imp_1 implementation_1

# creating branch implementation_2 at master~2 as you check it out in ../imp2:
git worktree add -b implementation_2 ../imp_2 master~2

And voilà! You're done.

With this setup, you'll have only one .git folder (in master/.git). Note that any branch can be checked out in a single worktree at a time.


you can create three clones of your repository and merge between those. forks in git are no different from branches the way they are merged and such. you can easily do:

git merge ../master
git pull ../imp_2

when cloning locally git will hardlink your objects and even save disk space