Search code examples
git-svntortoisegitgit-clone

Using "git svn" with two working trees


I am starting to use git as a Subversion client at work. For now I've been using TortoiseGit, more or less how I used to use TortoiseSvn, but with local commits, branches, merges, rebases, cherry picking.

It is a big project and switching a branch and recompiling everything takes too long. This is why I want to have two (or more) working trees corresponding to two branches of the Subversion project.

I wonder if it is possible to share the .git folder for the two working trees (its 5GB), or I need to clone the repository or maybe checkout it again from subversion (it took several hours).

From the git book it seems that interaction between two git repositories will not work well if they interact with svn as well (I don't know if this applies to my case):

Don’t rewrite your history and try to push again, and don’t push to a parallel Git repository to collaborate with fellow Git developers at the same time. Subversion can have only a single linear history, and confusing it is very easy. If you’re working with a team, and some are using SVN and others are using Git, make sure everyone is using the SVN server to collaborate – doing so will make your life easier.

I would like to have a single repository with all svn branches and all my local branches and I would like have several working trees to avoid the need to rebuild everything after switching branches. Is that possible?

I don't know much about "bare" or "shared" repos, remotes and clones, a basic example to set this up would be very helpful.


Solution

  • This is what I finally did:

    As johannes suggested, there is a script that solves my problem on Linux (http://nuclearsquid.com/writings/git-new-workdir/). But I am on Windows:

    • download the Windows port of the script from https://github.com/joero74/git-new-workdir
    • open a cmd as Administrator (git installs a Git bash that won't work with this script, you need to do it with cmd)
    • Add git to the path if you don't have it. In my case set PATH=%PATH%;"C:\Program Files (x86)\Git\bin"
    • execute the script. In my case I have a folder called Project (that has a .git folder in it): git-new-workdir.cmd .\Project .\Project2

    This creates a new folder Project2, with a working tree and a folder called .git. This .git folder has links to the original Project/.git so if I do some git svn fetch or create local branches or anything, both "copies" are updated at the same time (without push or pull). The working trees are different: if I switch branch in one, the other doesn't change and I can work on different branches at the same time.

    I just need to remember where the original .git is and never delete it.