title: How to use git on a continuous integration build server
body: <p>We have a build server which is designed to check-out a version of the code from git and build it.  Generally the server will check-out and build the <code>develop</code> branch, but it can be controlled by a GUI to perform a build of any specific branch or tag.</p>
  
  <p>Our git archive is large, so we only want to perform a <code>git clone</code> once.  So my question is: what sequence of git commands should be issued in order to bring the current working directory up-to-date with respect to the remote git archive.</p>
  
  <p>My initial naive attempt just performed <code>git checkout &lt;branch&gt;</code> followed by  <code>git pull</code>.  But this did not take into consideration all the artifacts created by the prior build which needed to be deleted as well as some automatic code modifications made by the build process e.g. to the version numbers in assembly files.</p>
  
  <p>So what I think we need is the command sequence to</p>
  
  <ol>
  <li>Get rid of any modifications to the local directory</li>
  <li>Update the local repository to include ALL commits from the remote server</li>
  <li>Checkout the named branch or tag</li>
  </ol>
  
  <p>Please bear in mind that the named branch or tag may not already be known in the local repository.  For example if a new <code>release/xxx</code> branch is created on the remote server, this will not be known <em>a priori</em> to the local build machine.  This is another one of the issues my naïve approach stumbled on.</p>
  
  <p>And finally, it's possible that the git server may occasionally have it's history <em>corrected</em>.  I'm sure this will be a rare event, but it would be desirable if the integration server didn't need any adjustment following a history rewrite.</p>
  
  <p>Many thanks</p>