[git] How do I undo a checkout in git?

I just checked out an earlier commit from my local git repo. I haven't made any changes to it, I was just looking at it. Now I want to go back to my latest commit - how do I do that?

The exact command I used to check it out:

git checkout e5dff6b3c5d704f9b598de46551355d18235ac08

Now when I type git log, at the top I see this checked out commit, but none of my later commits. Did I accidentally delete those?

This question is related to git

The answer is


To undo git checkout do git checkout -, similarly to cd and cd - in shell.


You probably want git checkout master, or git checkout [branchname].