Fix a detached head in git
So, let's say you have a detached branch with some change already done and you want to push those changes to master branch. How do you do that?
First, you let soak the changes in a brand new branch with whatever the name you want. I call it `detached`:
git branch detached
Move the HEAD with checkout:
git checkout detached
Now, all your changes are safe in the new local branch. So we can hop on the master branch and merge (or rebase) the previous branch with it:
git checkout master
git merge detached
Done! Now you have your changes on master and you can push them to the remote repo, if you are ready.
Did you find this post useful?
Remember that this website doesn’t make use of any trackers or analytics or adv so it doesn’t earn from your visits (moreover, it has a minimal environmental impact).
If you like this blog, refill my caffeine supplies by