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

Re: Bug: branch checkout is detached if the case doesn't match

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 20, 2021, 22:03 UTC
Message-ID
<87czsg429h.fsf@evledraar.gmail.com>
In-Reply-To
<CAKuVd4DfvEhXDUvxaU_jjNk8JSZANM8jpSEOxi1cbSAp23ohjg@mail.gmail.com>
On Sun, Jun 20 2021, Tim Hutt wrote:
Show 17 quoted lines
> If you try to switch to a branch (e.g. `master`), but get the case wrong, e.g:
>
>     git switch MASTER
>     git checkout MASTER
>     git switch Master
>     git checkout Master
>
> etc. then it autocorrects the case (bad idea but ok), but it also
> enables the `--detach` flag! In other words
>
>     git switch Master
>
> acts like
>
>     git switch -d master
>
> Very unexpected!

This behavior isn't intentionaly, but ultimately isn't with Git, but with your running of Git on a filesystem that doesn't respect POSIX semantics.

The default FS on OSX is case insensitive, we store the "master" reference (unpacked) under that name on the FS, so this is emergent behavior. Can you reproduce this after a:

    git pack-refs --all
?

Even after that we'll have a .git/HEAD, and I know on OSX e.g. "git log head...<branch>" unintentionally resolved to "HEAD" too at some point (probably still).

There's various workarounds in git's code to deal with funny behavior on OSX, but it's hard to catch them all as it means having to second-guess standard library calls. I think you're best off creating a case-sensitive partition on your computer and using git there if you want to avoid these cases entirely.

Show 15 quoted lines
> [System Info]
> git version:
> git version 2.32.0
> cpu: x86_64
> no commit associated with this build
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> uname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:14
> PST 2021; root:xnu-7195.101.1~3/RELEASE_X86_64 x86_64
> compiler info: clang: 12.0.5 (clang-1205.0.22.9)
> libc info: no libc information available
> $SHELL (typically, interactive shell): /bin/zsh
>
> [Enabled Hooks]
Previous: Tim HuttNext: Tim Hutt
Message 2 of 6 in “Bug: branch checkout is detached if the case doesn't match”
  1. Tim HuttJun 20, 2021
  2. Ævar Arnfjörð BjarmasonJun 20, 2021
  3. Tim HuttJun 21, 2021
  4. brian m. carlsonJun 23, 2021
  5. Tim HuttJun 23, 2021
  6. Ævar Arnfjörð BjarmasonJun 23, 2021

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.