6

I have cloned a big git repository (about 3.7g) that contains multiple branches. One of the branches is responsible to set up a Windows Installer (InnoSetup) and therefore, after I built the main program, I need to switch to the Installer branch.

Is there a possibility to have a single repository, but two separate HEADs in two different directories, so don't have to clone the repository twice?

  • what do you mean? head is referred to a branch, not a repo. – DonCallisto Jun 16 '16 at 08:18
  • I dont get why you would have that in one repository. Split it up in two repositories. – Xatenev Jun 16 '16 at 08:20
  • I'm fully aware that the structure is neither useful nor handy. I just came across this situation and was wondering if some kind of multiple heads is possible. – Thomas Raffelsieper Jun 16 '16 at 08:25
  • 5
    Git versions at or above 2.5 have `git worktree`, which can make multiple work-trees from a single repository. Each worktree has its own HEAD and index. See http://stackoverflow.com/q/31935776/1256452 (and incidentally, HEAD in Git is shouted :-) —when I read your question my first thought was Mercurial "heads"). – torek Jun 16 '16 at 09:33
  • That is exactly, what I was thinking of. I would mark this as correct answer, but it is just a comment. – Thomas Raffelsieper Jun 16 '16 at 10:53
  • @torek Please post it as the answer. – MicroVirus Jun 16 '16 at 11:21

1 Answers1

6

If your Git is version 2.5 or higher,1 you have a new command, git worktree. This has an add sub-command, which will make a new work-tree in another directory. Each such work-tree has its own HEAD and index (and various state files, such as those used with an in-progress git am, git rebase, and so on—basically all things reported by git status). See the documentation for details. Note that even in current versions of Git (2.8.x), git worktree is still somewhat experimental. It should work for this particular use case, though.

See also What would I use git-worktree for?


1I recommend at least 2.6, which fixes a handful of bugs. See every mention of "worktree" in the 2.6.0 release notes.

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775