git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Nick <oinksocket@letterboxes.org>
Cc: git@vger.kernel.org, Stephen Bash <bash@genarts.com>
Subject: Re: git push on tracking branches
Date: Mon, 27 Sep 2010 13:53:39 -0400	[thread overview]
Message-ID: <20100927175339.GA10650@sigill.intra.peff.net> (raw)
In-Reply-To: <4CA0D178.6070704@letterboxes.org>

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

      reply	other threads:[~2010-09-27 17:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100927175339.GA10650@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=bash@genarts.com \
    --cc=git@vger.kernel.org \
    --cc=oinksocket@letterboxes.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).