title: How to reattach a detached HEAD in GIT
body: <p>(I can see there are many questions about this but I haven't found one that solves my exact problem).</p>
  
  <p>I'm running gitlab-ci and when the runner checks out my code it does so as a detached head. Here is what I get when running a <code>git status</code> command in the runners directory.</p>
  
  <pre><code>git status
  # HEAD detached at 847fe59
  nothing to commit, working directory clean
  </code></pre>
  
  <p>What I need to do for what I am working on is to re-attach this head back to my develop branch and then <code>git pull</code> in the full repo for use in a docker container. I guess gitlab ci only checks out the last commit to save cloning down the full repo which is understandable.</p>
  
  <p>In my <code>.gitlab-ci.yml</code> file I've tried the following...</p>
  
  <pre><code>- git checkout origin/$CI_BUILD_REF_NAME
  - git pull
  </code></pre>
  
  <p>Which gives the following output in the console...</p>
  
  <pre><code>    $ git checkout $CI_BUILD_REF_NAME
      Switched to a new branch 'develop'
      Branch develop set up to track remote branch develop from origin.
  $ git pull
  You are not currently on a branch. Please specify which
  branch you want to merge with. See git-pull(1) for details.
  </code></pre>
  
  <p>Is there an easy way to reattach the head? Most of the solutions I've seen deal with the fact a change has been committed onto the detached head however this isn't the case for me. I just want to get my full <code>develop</code> branch in my docker container with all of my git history.</p>
  
  <p>Or if there is a way to stop gitlab ci from checking out the detached head that would also be great.</p>