Mot
Mot

Reputation: 29600

One Git repository, two working trees

Is it possible to have two working trees (two different branches) on the same local repository (== shared .git directory)?

Upvotes: 6

Views: 682

Answers (3)

Philip Oakley
Philip Oakley

Reputation: 14101

Yes. But you need to place the second branches workdir in a second directory, and hand manage the swap.

see Git man page:

--work-tree=<path>
Set the path to the working tree. It can be an absolute path or a path relative
to the current working directory. This can also be controlled by setting the 
GIT_WORK_TREE environment variable and the core.worktree configuration variable 
(see core.worktree in git-config(1) for a more detailed discussion).

This allows you to checkout to as many work tree/directories as you require, and check them back in in any order, against what ever branch you claim to have already checked out.

But don't be surprised if you make a few mistakes. It's a bit like running with scissors.

Upvotes: 2

mstrap
mstrap

Reputation: 17443

Probably alternates could be helpful here to share one object store among multiple .git/-directories. Check for 'objects/info/alternates' at:

http://www.kernel.org/pub/software/scm/git/docs/gitrepository-layout.html

Upvotes: 2

mipadi
mipadi

Reputation: 411390

No, you'd have to make two clones.

Upvotes: 1

Related Questions