title: Git workflow - changing branch and slow recompiles
body: <p>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. </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p><strong>update 3+ years later</strong></p>
  
  <p>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.</p>
  
  <p><strong>update 7+ years later</strong></p>
  
  <p>It looks like <a href="https://git-scm.com/docs/git-worktree" rel="noreferrer" title="git-worktree">git-worktree</a> is the replacement for git-new-workdir. To use:</p>
  
  <pre><code>cd ~/git/my-repo
  git worktree add ~/git/my-linked-repo
  </code></pre>