If I do
git checkout -b samename origin/samename
then tracking appears to work fine. If I do subsequent commits, I can then do
git push
and git pushed up my commits to origin fine.
However, if I do
git checkout -b diffname origin/samename
then tracking doesn’t work, despite this section of the pro git book:
$ git checkout -b sf origin/serverfix
Branch sf set up to track remote branch refs/remotes/origin/serverfix.
Switched to a new branch "sf"
Now, your local branch sf will automatically push to and pull from origin/serverfix
Git push just gives ‘Everything up to date’
What gives?
I am running git 1.7.1 on mac os x
Here’s the whole experiment for those that want to try it at home:
szbwood-mbp15:proj4_local bwood$ vi file1
szbwood-mbp15:proj4_local bwood$ git add file1
szbwood-mbp15:proj4_local bwood$ git commit -m"Created file 1"
[master (root-commit) 5d50289] Created file 1
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 file1
szbwood-mbp15:proj4_local bwood$ git push origin master:samename
Counting objects: 3, done.
Writing objects: 100% (3/3), 225 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /Users/bwood/work/gitplay/proj4_remote.git
* [new branch] master -> samename
szbwood-mbp15:proj4_local bwood$ git checkout -b samename origin/samename
Branch samename set up to track remote branch samename from origin.
Switched to a new branch 'samename'
szbwood-mbp15:proj4_local bwood$ vi file1
szbwood-mbp15:proj4_local bwood$ git commit -a
[samename a7af908] ..
1 files changed, 1 insertions(+), 0 deletions(-)
szbwood-mbp15:proj4_local bwood$ git push
Counting objects: 5, done.
Writing objects: 100% (3/3), 251 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /Users/bwood/work/gitplay/proj4_remote.git
5d50289..a7af908 samename -> samename
szbwood-mbp15:proj4_local bwood$ git checkout -b diffname origin/samename
Branch diffname set up to track remote branch samename from origin.
Switched to a new branch 'diffname'
szbwood-mbp15:proj4_local bwood$ vi file1
szbwood-mbp15:proj4_local bwood$ git commit -a
[diffname c5bbec1] ..
1 files changed, 1 insertions(+), 0 deletions(-)
szbwood-mbp15:proj4_local bwood$ git push
Everything up-to-date
The weird thing is, the config file looks fine..
[branch "samename"]
remote = origin
merge = refs/heads/samename
[branch "diffname"]
remote = origin
merge = refs/heads/samename
This isn’t about tracking.
git pushby default doesn’t use tracking at all. It pushes branches with matching names to the specified remote. There’s a config parameter to control this behavior:Again, the default is matching, so although you do have tracking set up in your first case, it’s just the matching names that tell it what to push. If you want, you can certainly set
push.defaulttotracking, and get the behavior you’re expecting.As for your quote from Pro Git… wow, Pro Git is generally a great resource. I haven’t read it all the way through (I tend to head straight for manpages and source code), but everything I’ve read is great; I’m surprised to see even a tiny mistake!