Chances are if you’ve been using Git as your source control weapon of choice, you’ve encountered the detached head issue at some point. I’ve seen even long time users of Git get stumped on this issue.
So onto the solution, how the heck do you get everything back to normal? We are going to dive into the terminal for this one, I am not sure if there are any Git GUI’s out there like GitKraken or Sourcetree that can handle these scenarios.
- Create a branch called “temp” by typing:
git branch temp
- Switch over to your new branch by checking it out:
git checkout temp
- Point the master pointer to the temp branch pointer (the-f means force):
git branch -f master temp
- Switch back to the
git checkout master
- Now we delete our temp branch:
git branch -d temp
- Push our new changes to the remote repository:
git push origin master
Provided nothing else messed up, things should be back to normal now.