Thomas Raffelsieper
Thomas Raffelsieper

Reputation: 574

Is it possible to have multiple HEADs within a single git repository?

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?

Upvotes: 6

Views: 6706

Answers (1)

torek
torek

Reputation: 488123

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.

Upvotes: 6

Related Questions