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

checkout/branch needs some extra safety around the --track option

From
Johan Herland <johan@herland.net>
Date
Feb 15, 2011, 17:52 UTC
Message-ID
<201102151852.03881.johan@herland.net>
Hi,

I just got a problem report from a Git user a $dayjob, who was confused about the following output from 'git push' (without arguments, in a repo with push.default == 'tracking'):

Show 6 quoted lines
> ----------------------------------------------------------------
> $ git push
> Total 0 (delta 0), reused 0 (delta 0)
> To .
>     c9e7b5a..1bf9fed  mybranch -> v0.99
> ----------------------------------------------------------------

After some investigations, I could reproduce his problem with the following commands:

$ git checkout -b mybranch --track v0.99 # Do work on mybranch $ git push

In other words. The branch was erroneously created with the --track option, setting up a bogus branch.mybranch config section. When pushing, this caused the v0.99 tag to be (unexpectedly, to him) updated in the local repo.

Obviously, this is rooted in user error, but it occurs to me that Git should be more helpful in this situation. I propose:

1. When given "--track", branch/checkout should verify that the tracked 
branch is indeed a branch (preferably a remote branch, although I guess 
tracking a local branch can make sense in some situations). At least, 
it should deny tracking a _tag_. Tracking a tag simply does not make 
sense at all (unless you expect the tag to move, in which case it 
should be a branch and not a tag).
2. 'git push' should not move tags by default (not even in your local 
repo). Moving tags might be ok if given the -f option (still a remote 
repo should be able to object). With the current version of Git, the 
following commands will transform an annotated tag into a lightweight 
tag with no warning:

$ git config push.default tracking $ git checkout -b foo --track $annotated_tag $ git push

...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Next: Junio C Hamano
Message 1 of 7 in “checkout/branch needs some extra safety around the --track option”
  1. Johan HerlandFeb 15, 2011
  2. Junio C HamanoFeb 15, 2011
  3. branch/checkout --track: Ensure that upstream branch is indeed a branchJohan Herland, Feb 16, 2011
  4. Junio C HamanoFeb 16, 2011
  5. branch/checkout --track: Ensure that upstream branch is indeed a branchJohan Herland, Feb 16, 2011
  6. Martin von ZweigbergkFeb 18, 2011
  7. Junio C HamanoFeb 18, 2011

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.