I’m working on a Git repository with two main branches and two main folders. One of these folders is very similar between the two branches, the other is very different. This means that, even if I’m just working on the common folder, switching between the two branches is slow due to all the updates required to the other folder.
Is it possible to switch the branch of a subfolder in a Git repository without switching the branch of the rest of the repository? In Subversion, I could just use svn switch on any subfolder, and everything would Just Work™, but I haven’t found an equivalent in Git.
Ideally, when I’m working in the folder that’s common to the two branches, I’d like to be able to switch branches in that folder, make commits to either branch, and do all the other useful Git goodness, without having to wait for the other folder to be more-or-less completely rewritten.
Just to complicate matters, I’m using git svn; the two main branches I mention are the trunk and a branch in the underlying Subversion repository.
I’ve found a new solution to this:
git-new-workdir. It doesn’t let me switch a subfolder, but it does let me have separate working directories which I can switch between instead of using a “switch” operation.It solves the underlying problem: I can have one working directory for each of the main branches, swap between them whenever I want with no cost, and the two working directories share the same Git repository, so I don’t need two separate clones as Ben Lee suggested in the comments to his answer.
To get at the script on my (Cygwin) system, I needed to download and install the Git source code; it’s in the
contribdirectory there.