2
git checkout origin/some_remote_branch
...
> You are in 'detached HEAD' state....

How do I later find out what I checked out?

ykaganovich
  • 14,736
  • 8
  • 59
  • 96
  • Is there a use case for this or did you just mistakenly type "origin/" and need a one time recovery? – Andrew C Oct 24 '14 at 00:45
  • This is for a specific usecase. I checked out a tag we released to a customer. I might make some changes to it; I might make a branch out of it later, I'm not sure... I just want to be able to tell where I am :) – ykaganovich Oct 24 '14 at 04:55
  • Newer versions of git do a much better job in `git status` output. For the tag case specifically you can always do `git describe`. – Andrew C Oct 24 '14 at 05:01

3 Answers3

1

One simple command: git status

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

In the case of a detached head, you'll get this message:

$ git status
HEAD detached at origin/master
Lucas Trzesniewski
  • 50,214
  • 11
  • 107
  • 158
  • This looks good, except I don't get the same message. The message I get looks like: # Not currently on any branch. Maybe I'm on an old git version? 1.7.12.4 and 1.8.2 give the same (checked out using 1.7.12.4) – ykaganovich Oct 24 '14 at 04:55
0

try: git status

It should tell you what branch you're on and the state of any changes you've made.

Codecraft
  • 8,291
  • 4
  • 28
  • 45
0

You should rather create a local branch based on the remote branch you want to check out.
Then, a git status would be more helpful (instead of the current "Not currently on any branch")

git checkout -b some_remote_branch origin/some_remote_branch

Otherwise, all you could do is list the branches which includes the commit you are currently at (in a detached HEAD situation):

git branch -r --contains <commit>

(as in "How to list branches that contain a given commit?")

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250