Git Detached Head

    If a HEAD has to be reset to a older version this is a possible workflow.

    The solution is from stackoverflow

    First checkout the version that should be the new HEAD.

    git checkout <SHA-1 id of commit>

    Now we create a temp branch and check it out.

    git checkout -b temp

    This is equivalent to git branch temp followed by git checkout temp.

    Now we want master (or an other branch) to point to it.

    git checkout -B master temp

    This is equivalent to git branch -f master tempfollowed by git checkout master.

    Now we can delete the temp branch:

    git branch -d temp

    Now we can push to a remote (-f might be needed):

    git push -f origin master


    • Category

    • Programming

    • Tags

    • Git
      Version Control

    • Created

    • 18. November 2015


    • Modified

    • 10. April 2022