What to do when you get detached from your head, you git.

I found myself wandering about detached from my head, fully committed. You don’t want to commit when detached from head, but I had.

I didn’t know how it happened, but there I was, headless. What a silly, silly git.

I reached out to a friendly spider and the answer was there in the web.
Before you wander back to your head, it is important to mount yourself to a branch, then you can use that branch to reattach your head quite easily.
Here is how the magic incantations go:

git checkout -b the_wanderer
git rebase master
git checkout master
git merge the_wanderer
git commit

I’ve tied the branch to where I am, then grabbed where I was and attached that, then bound everything back together.
Clear as mud? Already done git checkout master? Check the spellbook that inspired me.

But wait, there's more

5 thoughts on “What to do when you get detached from your head, you git.

  1. I use git daily, but I’ll be the first to admit that anything outside of the standard workflow alludes me.

    I think what caused my issue is that the parent repo contained an old submodule reference (i.e. the submodule had been updated, but the parent hadn’t, so the reference was out of date). I’d pulled down the main repo and the submodule, and started working on the submodule as if it were the most up to date version. So I’d been working on an old version of the submodule – and when it came to committing my changes git literally lost its head.

    Was quite a pain to sort but this post helped get through the most difficult bit!

    Thanks :)

Leave a Reply to Nathan Cancel reply

Your email address will not be published. Required fields are marked *