1

What's happening with my local Git branches? Here is the sequence of commands I ran:

$ git fetch --all
$ git branch
* feature/myfeature1
  master
  branch-dev
$ git branch -a
* feature/myfeature1
  master
  branch-dev
  remotes/origin/bugfix/bug-on-user
  remotes/origin/feature/myfeature2
$ git checkout origin/bugfix/bug-on-user
M       com.soc.data/.settings/org.eclipse.jdt.core.prefs
M       com.soc.data/META-INF/MANIFEST.MF
Note: checking out 'origin/bugfix/bug-on-user'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at d467d95... ...

$git branch
* (detached from origin/bugfix/bug-on-user)
   feature/myfeature1
   master
   branch-dev

Why is my branch detached? What did I do wrong?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Pracede
  • 4,226
  • 16
  • 65
  • 110
  • 1
    See http://stackoverflow.com/questions/25670173/why-does-git-tell-me-not-currently-on-any-branch-after-i-run-git-checkout-ori/25670296#25670296 – jub0bs Mar 19 '15 at 16:23

1 Answers1

2

You need to

git checkout bugfix/bug-on-user

not

git checkout origin/bugfix/bug-on-user

Otherwise it won't be a local branch... well, actually it will be a local branch, but not what you mean, it will be a remote-tracking-branch, which is a branch you should never work on directly, but which is use when pulling/fetching data from remote repositories.

blue112
  • 52,634
  • 3
  • 45
  • 54
  • `git checkout bugfix/bug-on-user` won't work, since `bugfix/bug-on-user` doesn't exist. Did you mean `git checkout -b bugfix/bug-on-user`? Besides, `origin/bugfix/bug-on-user` *is* local, in the sense that it lives in the local repo; it's just a special type of local branch (I like to call them *remote-tracking branches*, to distinguish them from *remote branches*) that is only meant to reflect the state of a remote branch, i.e. a branch living in a remote repo. – jub0bs Mar 19 '15 at 16:32
  • 1
    Actually `git checkout bugfix/bug-on-user` works most of the time, git seems clever enough to figure out it should be tracking the remote branch. – blue112 Mar 19 '15 at 16:43
  • You're right. I hadn't noticed. – jub0bs Mar 19 '15 at 16:45