“Not currently on any branch” after doing a commit

I did a checkout to an earlier commit:

git checkout 12345

Then back to the last commit:

  • Git: how can I have modified files and still checkout other branches?
  • “if” versus “switch”
  • Git: Deny deleting remote branch via push (like receive.denyDeletes), but only if branch is not fully merged
  • Keep files on working tree but make them available to any branch?
  • Git and working on multiple branches
  • Git: How to list commits on this branch but not from merged branches
  • git checkout 56789

    And then continued committing and I’m:

    Not currently on any branch.

    Perhaps, I should’ve done:

    git checkout master

    After the first checkout, instead of pointing to a commit id.

    Still, any idea how to get my latest commits into the master branch (which is a few commits behind)?


  • What if the owner of some repository on github has stopped working on some project but I want to contribute to it?
  • Failed Xcode Git Merge is stuck
  • git - Removed large file but checkout and .pack files still huge
  • “git merge -s theirs” needed — but I know it doesn't exist
  • Jenkins Invalid Git Revisions
  • Git rebase commit selection
  • 2 Solutions collect form web for ““Not currently on any branch” after doing a commit”

    When you do git checkout 12345 you will be in no branch state. Do not do that. This is meant for commit inspection rather than working in it.

    If you are on master and want to reset your master to the commit that you wanted, use git reset 12345 ( or supply --hard ) If you wanted to branch, use git checkout -b <name> <sha1> to create a branch at that point and start working there.

    Similarly while coming back, like you mentioned, you should have done git checkout master

    Now that you have committed over 56789, note down the commit over 56789, and then checkout master, and do:

    git reset <commit_over_56789>

    If I understand you correctly, your master branch is behind your most recent commit (56789), and you’d like to make it point to that.

    If that’s the case, doing:

    git branch -f master 56789

    will reset the master branch to point to that commit. git checkout master after that, and you should be good to go.

    Git Baby is a git and github fan, let's start git clone.