• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

How To Fix A Detached Head On A Git Repository

General · May 1, 2014

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 master branch: 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.

Dwayne

Leave a Reply Cancel reply

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mickey
Mickey
7 years ago

Nice, that really helped me a lot!
Between step 3 and step 4 you need to do a “git checkout master” as you the git command in step 4 would give you “error: Cannot delete the branch ‘temp’ which you are currently on.”

0
Antonio
Antonio
5 years ago

excellent resource!
Also: what Mickey said.

0
Jaka
Jaka
3 years ago

This is not working. I still have detached head!

2
Siddharth
Siddharth
3 years ago

Helpful!
Between step-3 and 4, we have to switch branch and then delete.

0

Primary Sidebar

Popular

  • I Joined Truth Social Using a VPN and Editing Some HTML to Bypass the Phone Verification
  • Testing Event Listeners In Jest (Without Using A Library)
  • How To Get The Hash of A File In Node.js
  • Thoughts on the Flipper Zero
  • Waiting for an Element to Exist With JavaScript
  • Handling Errors with the Fetch API
  • How To Get Last 4 Digits of A Credit Card Number in Javascript
  • How To Paginate An Array In Javascript
  • Wild Natural Deodorant Review
  • How To Install Eufy Security Cameras Without Drilling or Using Screws

Recent Comments

  • CJ on Microsoft Modern Wireless Headset Review
  • Dwayne on Microsoft Modern Wireless Headset Review
  • CJ on Microsoft Modern Wireless Headset Review
  • john on Microsoft Modern Wireless Headset Review
  • Dwayne on Why You Should Be Using globalThis Instead of Window In Your Javascript Code

Copyright © 2023 · Dwayne Charrington · Log in

wpDiscuz