So I kind of messed up royally and created a detached head because I wanted to go back to a previous version of my code. Problem is: now I can't push anything because my main branch is a detached head. If I try to merge the branches then it gets rid of the head and anything on it. How do I get the commits on my detached head back onto the master branch? I heard about this code: git merge HEAD@{1} but I was scared to try it without confirmation because I was afraid of what would happen. Anyone know how to do this?
because my main branch is a detached head
No, that’s not correct. A detached HEAD is when you have checked out a commit that is not a branch. So by definition, you are not on a branch if you have a detached HEAD.
I would suggest you to create a branch from your current (detached) HEAD, so you don’t lose any information but can move around freely again:
git checkout -b newbranch
After that, you will be on a non-detached HEAD again, on newbranch
, and you should be able to check out other branches and merge newbranch
in some other branch if necesary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With