Skip to content

Instantly share code, notes, and snippets.

@cmatskas
Created August 22, 2015 21:55
Show Gist options
  • Save cmatskas/c1a0bf77be83a681d7f2 to your computer and use it in GitHub Desktop.
Save cmatskas/c1a0bf77be83a681d7f2 to your computer and use it in GitHub Desktop.
Git merge detached head
$git checkout –b temp #makes a new branch from current detached HEAD
$git branch –f master temp #update master to point to the new <temp> branch
$git branch –d temp #delete the <temp> branch
$git push origin master #push the re-established history
@seanmavley
Copy link

Slight addition. You would need to switch to a different branch before you can delete the temp branch. So a $ git checkout master should be run before the delete of temp

@zaufi
Copy link

zaufi commented Jul 26, 2018

And one more ;-) Probably you need to do git branch --unset-upstream and then git push --set-upstream origin master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment