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

Re: git failing to create new branches, depending on the name

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Aug 8, 2009, 17:35 UTC
Message-ID
<alpine.LNX.2.00.0908081312140.2147@iabervon.org>
In-Reply-To
<4A7D9AA7.1030709@gmail.com>
On Sat, 8 Aug 2009, Artur Skawina wrote:
Show 21 quoted lines
> One of my build scripts, which takes a 'work' git tree, clones it to
> make a build tree, then creates an unique branch there and goes on
> to do the rest of the work, started mysteriously failing recently
> .
> Turns out git doesn't like the branch names that my script is
> choosing and git-checkout fails with a misleading fatal error.
> I don't remember changing the script recently and it used to work
> for months, something must have changed.
> 
> This is what i did while trying to find why the checkout is failing:
> 
> + git --version
> git version 1.6.4
> + rm -rf /tmp/build-tree
> + git clone -l -s -n -o askern --reference /tmp/work-tree /tmp/work-tree /tmp/build-tree
> Initialized empty Git repository in /tmp/build-tree/.git/
> + cd /tmp/build-tree
> + git branch -a | grep g90bc1a6 
> + git checkout -f -b branch-g90bc1a6 askern/release
> fatal: git checkout: branch branch-g90bc1a6 already exists
> # WTF?
Perhaps it shouldn't say "branch branch-g90bc1a6", but...
Show 7 quoted lines
> + (
> +  cd /tmp/work-tree
> +  git branch -a | grep g90bc1a6
> + )
> # nothing in parent repo either.
> + git checkout -f branch-g90bc1a6 
> Checking out files: 100% (29109/29109), done.

"branch-g90bc1a6" does already exist, in the sense that you can already check it out. It's probably a bad idea, from the point of view of having your repository make sense, to have a branch whose name is a valid name for a different commit (or, in any case, a commit not specified by the current value of the branch).

The check was added (restored, actually; it had been lost in the conversion to C) in order to prevent people from accidentally making local branches named things like "origin/master" when there's a remote branch named that.

Show 6 quoted lines
> Note: moving to 'branch-g90bc1a6' which isn't a local branch
> If you want to create a new branch from this checkout, you may do so
> (now or later) by using -b with the checkout command again. Example:
>   git checkout -b <new_branch_name>
> HEAD is now at 90bc1a6... Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
> # so where is coming from?

The official documentaion on specifying revisions is in the man page for git-rev-parse (it's referenced for a bunch of places, although this is obviously not the first place you'd think to look).

The error message should probably be improved to not imply that what's already using that name is a branch.

	-Daniel
*This .sig left intentionally blank*
Previous: Artur Skawina
Message 4 of 4 in “git failing to create new branches, depending on the name”
  1. Artur SkawinaAug 8, 2009
  2. Thomas RastAug 8, 2009
  3. Artur SkawinaAug 8, 2009
  4. Daniel BarkalowAug 8, 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.