Explanation of tracking branches is incorrect #43

cdlm opened this Issue Nov 10, 2010 · 4 comments


None yet
4 participants

cdlm commented Nov 10, 2010

http://progit.org/book/ch3-5.html#tracking_branches says:

Now, your local branch sf will automatically push to and pull from origin/serverfix.

But it's only true for git pull. Doing git push will create an origin/sf remote and push to an sf branch. To correctly push to serverfix you need git push origin sf:serverfix. Not sure if it's an actual discrepancy between the book and recent git releases, or if I'm just confused, but it's confusing :)

The explanation is correct actually. You can name your local branch whatever you want, Git will push to and pull from the remote branch it is tracking.

cdlm commented Nov 10, 2010

$ git clone foo bar
Cloning into bar...

$ cd bar
bar [master]$ git branches
* master                72d79d0 hello
  remotes/origin/HEAD   -> origin/master
  remotes/origin/master 72d79d0 hello

bar [master]$ git checkout -b foo origin/master 
Branch foo set up to track remote branch master from origin.
Switched to a new branch 'foo'

bar [foo]$ echo world >> hello; git ci -am world
[foo 3627cfc] world
 1 files changed, 1 insertions(+), 0 deletions(-)

bar [foo]$ git push
Counting objects: 5, done.
Writing objects: 100% (3/3), 249 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /Users/damien/Downloads/foo
 * [new branch]      HEAD -> foo

bar [foo]$ cd ../foo; git branches
  foo    3627cfc world
* master 72d79d0 hello

I'm not crazy I hope :)


jnavila commented Feb 3, 2013

A few points:

  1. It seems your command line snippet is fake. git branches does not exist.
  2. Anyway, your point is true. Tracking branches are only working for pull commands. For, push commands, if nothing is specified only branches with the same name are pushed. So if you type git checkout -b local_name remote/remote_name, only git pull will work. To force the push to be automatically matched, you will need to dig into config files.

So, in the end, this section is misleading and would need some rework.


schacon commented Oct 22, 2014

This is a good point and a mistake on my part. I believe this does work if you setup 'push.default' to 'upstream' but that's not very good for a triangular workflow. I will update the second edition to fix this error.

@schacon schacon closed this Oct 22, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment