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

Re: [funny] "git checkout -t origin/xyzzy" seems to misbehave

From
Alex Riesen <raa.lkml@gmail.com>
Date
Sep 21, 2008, 17:44 UTC
Message-ID
<20080921174438.GB3877@blimp.localhost>
In-Reply-To
<7v1vzd29i3.fsf@gitster.siamese.dyndns.org>
Junio C Hamano, Sun, Sep 21, 2008 10:23:00 +0200:
Show 28 quoted lines
> When you
> 
>  * are on a branch "foo" that is not "bar",
>  * have "origin/bar",
>  * and already have a local branch "bar",
> 
> "git checkout -t origin/bar" seems to misbehave.
> 
>     $ git clone -s git.junio victim-002
>     $ cd victim-002
>     $ git branch
>     * master
>     $ git checkout -t origin/next
>     Branch next set up to track remote branch refs/remotes/origin/next.
>     Switched to a new branch "next"
>     $ git checkout -t origin/master
>     fatal: A branch named 'master' already exists.
>     $ git branch
>       master
>     * next
>     $ git diff --cached --shortstat
>      60 files changed, 2378 insertions(+), 3412 deletions(-)
>     $ git diff --cached master
>     $ exit
> 
> The first "checkout -t" is fine.  The failed one seems to have already
> updated the index and the work tree when it notices that it cannot create
> a new branch.

Precisely this (branch already exists) case is easy to handle with a resolve_ref in builtin-checkout.c:switch_branches.

The other errors will still leave index and working tree in this state: branch.c:create_branch does not cleanup in case of errors, it just dies.

Previous: Junio C HamanoNext: Daniel Barkalow
Message 2 of 3 in “[funny] "git checkout -t origin/xyzzy" seems to misbehave”
  1. Junio C HamanoSep 21, 2008
  2. Alex RiesenSep 21, 2008
  3. Daniel BarkalowSep 21, 2008

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.