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

Creating tracked branches

From
Petr Baudis <pasky@suse.cz>
Date
Apr 22, 2010, 11:49 UTC
Message-ID
<20100422114924.GH3563@machine.or.cz>
In-Reply-To
<7vy6gf52d1.fsf@alter.siamese.dyndns.org>
On Thu, Apr 22, 2010 at 01:16:10AM -0700, Junio C Hamano wrote:
Show 15 quoted lines
> Petr Baudis <pasky@suse.cz> writes:
> 
> > On Wed, Apr 21, 2010 at 07:57:17PM -0400, Aghiles wrote:
> >> On Wed, Apr 21, 2010, Randal L. Schwartz  wrote:
> >> >    git checkout -b test origin/test
> > ...
> > So, do I understand it right that there is still no canonical syntax to
> > check out local branch tracking a remote one of the same name, without
> > spelling out the branch name twice?
> 
> Only if you don't count Dscho's DWIM.
> 
>     $ git checkout tr/word-diff
>     Branch tr/word-diff set up to track remote branch tr/word-diff from origin.
>     Switched to a new branch 'tr/word-diff'
Ugh. Right, so _this_ is what kept me from ever learning the proper way:
  (i) If you do `checkout B`, it will track remote branch B if it exists.
  (ii) If you do `checkout -b B`, it will never auto-track anything.
  (iii) If you do `git checkout -t -b B`, it will auto-track your current
_local_ branch.

This keeps getting me really confused, I hope I will remember it now for good, but I have seen others having trouble with this as well. I don't have immediate ideas that would do less harm than good to fix this up...

perhaps except changing (iii) to auto-track the remote branch B if it exists and require tracked branch name if it doesn't - the current default seems pretty much useless to me for usual cases. (I can imagine a scenario where it would be useful, but not a common scenario where this would be useful default.)

P.S.: The "--track without -b implies branch creation" sentence in git-checkout(1) seems to be plain wrong?

-- 
				Petr "Pasky" Baudis
http://pasky.or.cz/ | "Ars longa, vita brevis." -- Hippocrates
Previous: Junio C HamanoNext: Andreas Schwab
Message 19 of 22 in “git pull behavior changed?”
  1. AghilesApr 21, 2010
  2. Sverre RabbelierApr 21, 2010
  3. AghilesApr 21, 2010
  4. AghilesApr 21, 2010
  5. Sverre RabbelierApr 21, 2010
  6. Matthieu MoyApr 21, 2010
  7. AghilesApr 21, 2010
  8. Matthieu MoyApr 21, 2010
  9. AghilesApr 21, 2010
  10. Jeff KingApr 22, 2010
  11. AghilesApr 22, 2010
  12. Jeff KingApr 22, 2010
  13. AghilesApr 22, 2010
  14. Jeff KingApr 22, 2010
  15. Randal L. SchwartzApr 21, 2010
  16. AghilesApr 21, 2010
  17. Petr BaudisApr 22, 2010
  18. Junio C HamanoApr 22, 2010
  19. Creating tracked branchesPetr Baudis, Apr 22, 2010
  20. Andreas SchwabApr 22, 2010
  21. Petr BaudisApr 22, 2010
  22. AghilesApr 22, 2010

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.