Take the 2-minute tour ×

I did a checkout to an earlier commit:

git checkout 12345

Then back to the last commit:

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)?


share|improve this question

2 Answers 2

up vote 10 down vote accepted

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>
share|improve this answer
I find your answer more informative. Thanks :-) –  Albus Dumbledore Nov 26 '11 at 19:17
+1. 'git checkout master' was all I needed. –  Tyler Collier Jun 17 '12 at 3:08

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.

share|improve this answer
One can also simply git checkout master && git rebase 56789, assuming the working copy is clean. –  Romain Nov 25 '11 at 14:10
Perfect. Thanks a lot, Mat and Romain! –  Albus Dumbledore Nov 25 '11 at 16:45
Thanks a lot, worked for me. I personally find this answer more useful than the other one. –  Andrei LED Apr 7 '13 at 17:12

Your Answer


