Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 30
    Checking out a remote branch seems like the most common way to accidentally do this; another common way is to check out branch-name@{n}, the nth previous position of branch-name. But no matter what, at some point there must've been a git checkout <rev>. If that doesn't ring a bell, then probably you did what Will mentioned - tried to do git checkout <file> and managed to specify a revision by accident.
    – Cascabel
    Commented Oct 19, 2010 at 13:25
  • 3
    For undoing a detached HEAD state, see Fix a Git detached head?.
    – user456814
    Commented May 30, 2014 at 5:15
  • 11
    Also happens if you accidentally type git checkout remotes/origin/my-branch instead of git checkout my-branch or git checkout origin/my-branch. Commented Nov 20, 2019 at 12:54
  • @adam Libusa,Thanks it worked for me. What is the difference between git checkout remotes/origin/my-branch and git checkout my-branch. Is it not the same. but what you said worked for me. Out of curiosity I am asking. Commented Mar 17, 2020 at 7:32
  • @karunakarbhogyari The difference between git checkout my-branch and git checkout origin/my-branch is explained here: stackoverflow.com/a/30578803/1180977. As for the first case, remotes/origin/my-branch, I'd find it reasonable for git to behave similarly for all its commands. git show handles such branch names fine. I'd go as far as call it a bug, or at least an inconsistency in git-cli. Commented Mar 20, 2020 at 15:36