git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git push on tracking branches
       [not found] <6958088.371432.1285602164529.JavaMail.root@mail.hq.genarts.com>
@ 2010-09-27 16:00 ` Stephen Bash
  2010-09-27 16:05   ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Bash @ 2010-09-27 16:00 UTC (permalink / raw)
  To: Git Mailing List

Hi all-

A coworker alerted me to some strange behavior with git push on tracking branches (maybe a documentation error?).  Pro Git (http://progit.org/book/ch3-5.html) says:

"To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name:
   $ 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."

When I do this on my local machine (current master on Mac 10.6.4):

snowg5-2:temp stephen$ git clone ssh://bash@penguin/home/git/repos/test-repo.git
Cloning into test-repo...
warning: templates not found /Users/stephen/share/git-core/templates
remote: Counting objects: 100109, done.
remote: Compressing objects: 100% (23394/23394), done.
remote: Total 100109 (delta 76733), reused 99567 (delta 76231)
Receiving objects: 100% (100109/100109), 620.24 MiB | 28.36 MiB/s, done.
Resolving deltas: 100% (76733/76733), done.
snowg5-2:temp stephen$ cd test-repo
snowg5-2:test-repo stephen$ git checkout -b tmp origin/real-branch-name
Branch tmp set up to track remote branch real-branch-name from origin.
Switched to a new branch 'tmp'
... edit some files ...
snowg5-2:test-repo stephen$ git add -u .
snowg5-2:test-repo stephen$ git commit -m "made some changes"
[tmp 0440ace] made some changes
 1 files changed, 1 insertions(+), 0 deletions(-)
snowg5-2:test-repo stephen$ git push
Everything up-to-date
snowg5-2:test-repo stephen$ git rev-parse tmp
0440ace51b4ab18eee39305cd2af070f572e38d7
snowg5-2:test-repo stephen$ git ls-remote origin real-branch-name
92ebff3a7c332079bcbf84e9cf699ab635e6ba3c	refs/heads/real-branch-name
snowg5-2:test-repo stephen$ git --version
git version 1.7.3.2.g9027fa
snowg5-2:test-repo stephen$ 

Git doesn't push the change.  If I either use 
  a) git checkout --track origin/real-branch-name 
or
  b) git checkout -b real-branch-name origin/real-branch-name
the push succeeds.

Was the behavior of git push intentionally changed or is this a bug?

Thanks,
Stephen

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git push on tracking branches
  2010-09-27 16:00 ` git push on tracking branches Stephen Bash
@ 2010-09-27 16:05   ` Jeff King
  2010-09-27 16:14     ` Stephen Bash
  2010-09-27 17:16     ` Nick
  0 siblings, 2 replies; 5+ messages in thread
From: Jeff King @ 2010-09-27 16:05 UTC (permalink / raw)
  To: Stephen Bash; +Cc: Git Mailing List

On Mon, Sep 27, 2010 at 12:00:41PM -0400, Stephen Bash wrote:

> A coworker alerted me to some strange behavior with git push on tracking branches (maybe a documentation error?).  Pro Git (http://progit.org/book/ch3-5.html) says:
> 
> "To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name:
>    $ 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."

That has never been the case by default. Push has always defaulted to
pushing all matching branches (so of course if you use the same name, it
will end up pushing to the tracking branch).  However, you can do:

  git config --global push.default tracking

to explicitly change the default to push the current branch to its
upstream. See the entry for "push.default" in "git help config".

It may be that Pro Git suggested setting up that config earlier. If not,
you should probably submit a bug report for the book.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git push on tracking branches
  2010-09-27 16:05   ` Jeff King
@ 2010-09-27 16:14     ` Stephen Bash
  2010-09-27 17:16     ` Nick
  1 sibling, 0 replies; 5+ messages in thread
From: Stephen Bash @ 2010-09-27 16:14 UTC (permalink / raw)
  To: Jeff King; +Cc: Git Mailing List

----- Original Message -----
> From: "Jeff King" <peff@peff.net>
> To: "Stephen Bash" <bash@genarts.com>
> Cc: "Git Mailing List" <git@vger.kernel.org>
> Sent: Monday, September 27, 2010 12:05:48 PM
> Subject: Re: git push on tracking branches
> On Mon, Sep 27, 2010 at 12:00:41PM -0400, Stephen Bash wrote:
>
> > Now, your local branch sf will automatically push to and pull from
> > origin/serverfix."
> 
> That has never been the case by default. Push has always defaulted to
> pushing all matching branches (so of course if you use the same name,
> it
> will end up pushing to the tracking branch). However, you can do:
> 
> git config --global push.default tracking
> 
> to explicitly change the default to push the current branch to its
> upstream. See the entry for "push.default" in "git help config".

Thanks for the clarification!

Stephen

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git push on tracking branches
  2010-09-27 16:05   ` Jeff King
  2010-09-27 16:14     ` Stephen Bash
@ 2010-09-27 17:16     ` Nick
  2010-09-27 17:53       ` Jeff King
  1 sibling, 1 reply; 5+ messages in thread
From: Nick @ 2010-09-27 17:16 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Stephen Bash

On 27/09/10 17:05, Jeff King wrote:
> On Mon, Sep 27, 2010 at 12:00:41PM -0400, Stephen Bash wrote:
> 
>> A coworker alerted me to some strange behavior with git push on tracking branches (maybe a documentation error?).  Pro Git (http://progit.org/book/ch3-5.html) says:
>>
>> "To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name:
>>    $ 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."
> 
> That has never been the case by default. Push has always defaulted to
> pushing all matching branches (so of course if you use the same name, it
> will end up pushing to the tracking branch).  However, you can do:
> 
>   git config --global push.default tracking
> 
> to explicitly change the default to push the current branch to its
> upstream. See the entry for "push.default" in "git help config".

The "tracking" setting does seem more sensible and intuitive, given that current
git practice requires setting up explicit tracking relationships between branches.

For example, I find it surprising, perhaps even alarming, that by default, git
will try and push my changes on branch A to the branch origin/A - even if I
created it to track origin/B.  Why allow the possibility of A tracking a
non-matching branch origin/B, and have the default push setting ignore that?

Not only that, but I frequently get asked by puzzled colleagues, new to git, why
"git push" seems to fail all the time when they're pushing their changes.  (The
errors arise because of the default "matching" setting: many of the matching
branches fail to push cleanly because the remote branch has silently changed. My
latest answer is to tell them to set push.default to "tracking", or to do that
for them.)


I'm curious: why isn't "tracking" the default and recommended option?
"Historical reasons" might explain the first, but not the second.


- Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git push on tracking branches
  2010-09-27 17:16     ` Nick
@ 2010-09-27 17:53       ` Jeff King
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff King @ 2010-09-27 17:53 UTC (permalink / raw)
  To: Nick; +Cc: git, Stephen Bash

On Mon, Sep 27, 2010 at 06:16:40PM +0100, Nick wrote:

> The "tracking" setting does seem more sensible and intuitive, given that current
> git practice requires setting up explicit tracking relationships between branches.

It depends on your workflow. If you consider push to be a way of moving
commits in your private repo to a public publishing point, then matching
makes a lot more sense. But if you are emulating a centralized VCS
topology where you replace "svn commit" with "git commit && git push",
then probably pushing HEAD or "tracking" makes more sense.

The former is how git was originally conceived by Linus, and how many
people still use it (notably the kernel and git itself work this way).
But obviously yes, there are lots of people who use it more in the
latter way.

> For example, I find it surprising, perhaps even alarming, that by default, git
> will try and push my changes on branch A to the branch origin/A - even if I
> created it to track origin/B.  Why allow the possibility of A tracking a
> non-matching branch origin/B, and have the default push setting ignore that?

What if I create a topic branch from the master branch, like:

  $ git checkout -b topic origin/master

Now I want to publish my topic for others to see. What should the
behavior be?

With matching, I can do:

  $ hack hack hack
  $ git push ;# oops, we push nothing, because topic is not
              # already published
  $ git push origin topic ;# now topic is published under its
                           # own name
  $ hack hack hack
  $ git push ;# topic is synced to its published version,
              # even though its upstream remains origin/master

With tracking, I get:

  $ hack hack hack
  $ git push ;# we just pushed topic commits to master!

So again. It depends on workflow. Do you think of a branch with a
different name than its upstream as a separate topic based on that
upstream? Or do you think of it as a local version of upstream, simply
with a different name?

> Not only that, but I frequently get asked by puzzled colleagues, new to git, why
> "git push" seems to fail all the time when they're pushing their changes.  (The
> errors arise because of the default "matching" setting: many of the matching
> branches fail to push cleanly because the remote branch has silently changed. My
> latest answer is to tell them to set push.default to "tracking", or to do that
> for them.)

Yeah, one confusing aspect of matching is that it pushes things besides
the HEAD you are on. But I would argue that setting push.default to
"current" is safer than tracking. It pushes only HEAD to a ref of the
same name. In the case that you name your branch after the upstream
branch, this is the same as tracking. In the case that you have named it
something else, it assumes it is acting as a feature branch built on the
upstream, but will never accidentally push feature commits onto the
upstream branch.

> I'm curious: why isn't "tracking" the default and recommended option?
> "Historical reasons" might explain the first, but not the second.

Historical reasons. :)

If you want to read more, there was a lot of discussion on this about a
year and a half ago, which led to push.default being created. My quick
search came up with this thread:

  http://thread.gmane.org/gmane.comp.version-control.git/112757

but I seem to recall there being more philosophical discussion around
the topic, too. You might have to dig around in that general timeframe
of the list archive.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-09-27 17:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <6958088.371432.1285602164529.JavaMail.root@mail.hq.genarts.com>
2010-09-27 16:00 ` git push on tracking branches Stephen Bash
2010-09-27 16:05   ` Jeff King
2010-09-27 16:14     ` Stephen Bash
2010-09-27 17:16     ` Nick
2010-09-27 17:53       ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).