git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] push: Learn to set up branch tracking with '--track'

From
Jeff King <peff@peff.net>
Date
Jan 29, 2009, 22:33 UTC
Message-ID
<20090129223308.GB12871@coredump.intra.peff.net>
In-Reply-To
<alpine.DEB.1.00.0901291438030.3586@pacific.mpi-cbg.de>
On Thu, Jan 29, 2009 at 02:38:43PM +0100, Johannes Schindelin wrote:
Show 10 quoted lines
> When pushing a branch to a remote repository that the remote side did
> not know beforehand, it is often handy to set up the branch tracking
> such that
> 
> 	$ git checkout xyz
> 	$ git push --track origin xyz:abc
> 	$ git pull
> 
> will pull the branch 'abc' from the remote 'origin' into the branch
> 'xyz'.

What if "xyz" is a tag? Right now, the patch generates a bogus config section. Yes, you can say "don't use --track, then". But I can think two reasons why that isn't acceptable:

  1. You might be pushing multiple things, one of which is a branch
     and one of which is not.
  2. This is likely to grow a related config variable, similar to
     branch.autosetupmerge.

How about "git push --track origin HEAD"? This also generates bogus config. How about "git push --track origin refs/heads/*:refs/heads/*"? Also bogus.

It looks like you catch "git push --track --all". So at least there is no bogus config generated. But it would be nice to translate this to "create a tracking branch for everything I pushed".

So I think this patch is going about it the wrong way. Instead of parsing the refspec, I think you actually want to look at what we _do_ push (or at least try to push -- probably even uptodate refs should also have tracking established), and use that. Then you will have wildcards expanded, --all handled, etc. And I suspect all you have to do is iterate over the result of match_refs (which we call later), which should be even easier (because you don't have to parse the refspecs yourself). But I haven't looked carefully.

> +		if (!err && track)
> +			setup_tracking(transport->url);

Wouldn't the remote name (if we have one) be preferable to the URL? As it is, doing "git push --track origin master" results in

  [branch "master"]
    remote = $YOUR_URL_FOR_ORIGIN
    merge = refs/heads/master
which means that:
  1. If you ever change remote.origin.url, it will not propagate to your
     branch section.
  2. When you fetch, you are fetching into FETCH_HEAD, meaning your
     tracking refs are not updated.
-Peff
Previous: Johannes SchindelinNext: Jeff King
Message 5 of 15 in “push: Learn to set up branch tracking with '--track'”
  1. push: Learn to set up branch tracking with '--track'Johannes Schindelin, Jan 29, 2009
  2. Sverre RabbelierJan 29, 2009
  3. Johannes SchindelinJan 29, 2009
  4. Johannes SchindelinJan 29, 2009
  5. Jeff KingJan 29, 2009
  6. Jeff KingJan 29, 2009
  7. Johannes SchindelinJan 30, 2009
  8. Jeff KingJan 30, 2009
  9. Johannes SchindelinJan 30, 2009
  10. Jeff KingJan 30, 2009
  11. Johannes SchindelinJan 30, 2009
  12. Jeff KingFeb 2, 2009
  13. Johannes SchindelinFeb 2, 2009
  14. Jeff KingFeb 6, 2009
  15. Johannes SchindelinFeb 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.