0

I checked out someone else's branch and tracking it.

git checkout --track origin/foo

However, even though I checked out a different branch (not the master branch), why is HEAD still pointing to master?

When I type git branch -a, I get this. So I can't do things like git reset HEAD^ --hard

  master  
* foo  
  remotes/origin/HEAD -> origin/master  
  remotes/origin/foo  

I basically want to check out someone else's branch, and work on it. Also, commit and push into his branch.

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
Mike Huang
  • 15
  • 2
  • Will I be able to commit to this branch ? even if this branch is generated by another user ? I saw some post like you need to put `-u` option to `git push` ? – Mike Huang Oct 25 '16 at 18:30

2 Answers2

1

You should just be able to git checkout foo, and it will automatically know to track the correct upstream branch.

eddiem
  • 1,030
  • 6
  • 9
0

HEAD isn't pointing to master. This output:

* foo

means that your local HEAD is pointing to foo. The asterisk (*) represents HEAD.

You may have been confused by this line:

 remotes/origin/HEAD -> origin/master

which means that the remote HEAD is pointing to the remote master. This has no effect on your local HEAD.

As @eddiem mentioned, in the future, to check out a local branch that tracks origin/foo, just do:

git checkout foo

(This assumes you don't already have a local branch called foo.)

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67