Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git tracking doesn't work with different local and remote names?

Tags:

git

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
like image 267
bruce Avatar asked Oct 14 '22 21:10

bruce


1 Answers

This isn't about tracking. git push by 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:

push.default

Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:

  • nothing - do not push anything.
  • matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.
  • tracking - push the current branch to its upstream branch.
  • current - push the current branch to a branch of the same name.

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.default to tracking, 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!

like image 178
Cascabel Avatar answered Oct 17 '22 00:10

Cascabel