Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One Git repository, two working trees

Tags:

git

msysgit

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

like image 494
Mot Avatar asked Nov 09 '12 17:11

Mot


2 Answers

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

like image 122
mstrap Avatar answered Sep 22 '22 01:09

mstrap


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.

like image 33
Philip Oakley Avatar answered Sep 25 '22 01:09

Philip Oakley