Question

I work on a large Scala project where we use Git for version control. My workflow is to work on new features in my own branch and switch when needed. Various releases of the code are in their own branches. All very standard.

If I have to fix a bug in a certain version of the code, I'll switch to the correct branch, fix the bug, commit then switch back to where I was.

The problem is that although git is instant at switching to another branch once I'm there I have to recompile the code. Which takes several minutes. Then fix the bug, switch back to my own branch and do another recompile, which takes another few minutes. It seems to defeat the purpose of Git being so fast.

Has anyone else encountered this? Are there ways around it. I'm sure it's not a Scala specific problem (although Scala is epically slow at compiling).

update 3+ years later

I've been using @djs answer (git-new-workdir) for the last few years. It's worked very well for me. I have a master directory and several other directories (like production, next-release etc) that I switch to when I need to do work there. There's very little overhead and it means you can quickly switch to say, production, to test something, then switch back to what you were working on.

update 7+ years later

It looks like git-worktree is the replacement for git-new-workdir. To use:

cd ~/git/my-repo
git worktree add ~/git/my-linked-repo
Was it helpful?

Solution

Assuming you don't want to change your build process (hash-based instead of timestamped), you might want to look at the git-new-workdir script in the contrib directory of git source. Like the clone suggestion, you'll get multiple working copies, but instead of two independent repositories, you'll get one with multiple working copies. So, no pushing and pulling between local repositories.

It's a shell script and only runs on unix-like systems, but the concept can be replicated on modern versions of Windows.

OTHER TIPS

Assuming that your build system isn't overzealous about dependencies (maybe it thinks it needs to rebuild when it doesn't actually), the primary way to work around this is to clone your repository:

git clone my-repo my-repo2

You can then work in your extra clone, and push from it back into your main one. (You should only push to branches which aren't checked out, but that's the whole point here. You could also pull or even fetch and reset or branch -f if you wanted.)

And this won't really take up a lot of space, either; Git hardlinks the objects within the repository for local clones, so the extra space will just be the extra checked-out copy.

You could try using different target directories for different branches by overriding the outputDirectoryName. Maybe picking up the git branch name and setting the output directory to target-<branch>; although that would mean every new branch starts from scratch.

You can improve scala compile times drastically with by using [sbt][1] or the "fast scala compiler". Both allow to keep the compiler in memory, which improves compile times enormously.

Using one directory per branch allows to avoid so many recompiles. But that workflow is better supported by mercurial.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top