Git - separate folder for each branch. Setting it up

What you want to achieve has become simpler (or even trivial) since git 2.5 introduced the git worktree command.

Basically, your your git repo has now completely free number of checked out branches, called work tree:

  • 0 (a bare repo − roughly just the contents of your repo’s .git directory)
  • 1 (a normal repo − your code in the tree, the git directory under .git)
  • n > 1, a normal repo where you added n-1 worktrees (in arbitrary paths outside of your repo, and with a .git file pointing to your repo’s git directory)

If your repo already contains your branch, you can do:

git worktree add <path to branch> <branch name>

Or, if that branch isn't created yet and you want to branch off master:

git worktree add -b <new branch name> <path to branch> master

Note that you can't checkout a branch in several directories simultaneously.


I think that you might have to create all the branch in your repo

$ git branch <name_of_your_new_branch>

Then create all your folders and in each of your folder Clone the repo but Checkout the appropriate branches.

Each folder should / may track only the appropriate branch

Step 1 $ git branch [name_branch#1]

Step 2 $ git branch [name_branch#2]

Step 3 $ git branch [name_branch#3]

...

Step 4 $ git push --all
Step 5 md Folder #2
Step 6 $ git clone [URL]
Step 7 $ git checkout [name_branch]