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

Re: git checkout creates strange '(null)'-branch

From
Junio C Hamano <gitster@pobox.com>
Date
May 8, 2012, 15:05 UTC
Message-ID
<7vhavqzpa3.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CABPQNSZbgZsQBReSqOskNQ4oZokHSibVr=yHdn6oSFjtdRvVVA@mail.gmail.com>
Erik Faye-Lund <kusmabite@gmail.com> writes:
> Before this commit, the checkout would error out with "fatal: You are
> on a branch yet to be born". Perhaps abe1998 was too optimistic about
> allowing this, and something like this would be in order?
Show 15 quoted lines
> ---8<---
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 23fc56d..35924d4 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -1091,7 +1091,7 @@ int cmd_checkout(int argc, const char **argv,
> const char *prefix)
>  	if (opts.writeout_stage)
>  		die(_("--ours/--theirs is incompatible with switching branches."));
>
> -	if (!new.commit) {
> +	if (!new.commit && opts.new_branch) {
>  		unsigned char rev[20];
>  		int flag;
> ---8<---

The patch looks like it will avoid flipping the HEAD, and in that case we would go to switch_branches() codepath and will resurrect the old error message, so it seems correct.

Thanks for digging.
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 12 in “git checkout creates strange '(null)'-branch”
  1. Erik Faye-LundMay 8, 2012
  2. Johannes SixtMay 8, 2012
  3. Erik Faye-LundMay 8, 2012
  4. Andreas SchwabMay 8, 2012
  5. Junio C HamanoMay 8, 2012
  6. Erik Faye-LundMay 10, 2012
  7. Junio C HamanoMay 10, 2012
  8. Junio C HamanoMay 8, 2012
  9. Junio C HamanoMay 8, 2012
  10. Junio C HamanoMay 8, 2012
  11. Erik Faye-LundMay 8, 2012
  12. Junio C HamanoMay 8, 2012

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.