title: How can I cache untracked (binary) files associated to a branch?
body: <p>Assume I am one of many developers working with git on a huge code project, which has an <strong>incredibly long compilation time</strong>. </p>
  
  <p>Now, my personal day-to-day changes are usually limited, and the codebase is decently modular, which means that as far as my <em>personal</em> work is concerned, <strong>compiling from scratch is a price that only has to be paid once</strong>. Afterwards, I can recompile only the modules I modified.</p>
  
  <p>On the other hand, <strong>I frequently have to fix bugs in</strong> (at least two) <strong>branches which reflect states of the codebase completely distinct from the branch I work on</strong>. Those two branches are indeed the result of work from the entire development team, and often have entire modules rewritten or added. <strong>Having compiled everything before pushing a bugfix is mandatory</strong>. </p>
  
  <p>My first approach was to switch from my development branch every time a bugfix is needed, then clean, bugfix, recompile from scratch, push, switch back to the original branch, clean again, recompile - <strong>the delay for doing this is intolerable</strong>.</p>
  
  <p>I then moved to <strong>keeping three separate checkouts of the codebase on my machine</strong>. This solves the "<em>costly recompilation</em>" problem (my changes in every branch are incremental again), but it makes the question "what am I developing on right now ?" more complex to answer (since it depends on the current directory), and it makes synchronization of these three copies complex (it multiplies all the routine <code>push</code>/<code>remote update</code>/<code>pull</code> commands I have to do by three).</p>
  
  <p>A simpler solution would be <strong>to have the ability to save the state of a directory</strong> (untracked, where I generate compiled files) <strong>every time my checkout "leaves"a branch, and to recall the state of that directory, if it exists, every time I "enter"</strong> (checkout) <strong>a branch</strong>.</p>
  
  <ul>
  <li>Are there git commands that would help me achieve this behavior ?</li>
  <li>If not, is there a tool that would allow me to do that ?</li>
  <li>If not, does git provide checkout hooks that could help me script this behavior ?</li>
  </ul>