-2

Suppose I am on a branch named main in git and we can confirm it by git branch and git log commands. Screen shot of git bash.

But as branch names are case-insensitive in git. So, when we switch to any branch using git switch using its case-insensitive name, e.g., Horror in case of horror, git doesn't highlight the current branch in case of git branch and HEAD doesn't point to any branch in the case of git log command.
Screen shot of git bash

I was expecting that after switch to a branch by using its case-insensitive name, git should highlight that branch as current branch.

  • 1
    Git branch names are not case-insensitive. They're case sensitive, especially on Linux / Unix. See https://stackoverflow.com/a/38494084/19276569 – juanpethes Jun 28 '23 at 18:51

1 Answers1

0

Branch names, like all refs in Git, are case sensitive. They are often stored in the file system, which means that on some systems, it is not generally possible to store two names differing in case (by whatever means that file system determines that). However, they remain case sensitive, and Git will not consider two names differing in case to be identical.

Note that when references are packed into the packed-refs file, they are not stored with their names as file names, so every attempt to access them in a case-insensitive way will fail. There is a future design for references, called reftable, that will never store names in the file system and thus with that design references can never be treated case insensitively.

I should also point out that references are also not guaranteed to be in UTF-8, since they can contain bytes not valid in UTF-8. (However, if you choose non-UTF-8 names, you're in for a world of pain.) Even if you assumed they were in Unicode, in general it is impossible to properly case-fold Unicode text in a locale-insensitive way, so Git doesn't try to do that.

If you try to treat references in a case-insensitive way, it will break, as you've seen, so your best bet is to avoid that.

bk2204
  • 64,793
  • 6
  • 84
  • 100