How To Fix A Detached Head On A Git Repository
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?
- Step 1. Create a branch called “temp” by typing: git branch temp
- Step 2. Switch over to your new branch by checking it out: git checkout temp
- Step 3. Point the master pointer to the temp branch pointer (the-f means force): git branch -f master temp
- Step 4. Now we delete our temp branch: git branch -d temp
- Step 5. Push our new changes to the remote repository: git push origin master
Provided nothing else messed up, things should be back to normal now.