86

I have a really straightforward set of git commands that is resulting in some curious behavior:

Show my current local branches, and see that I'm on release/beta1:

$ git branch
  develop
  master
* release/beta1

Create a bugfix/somefeature branch from release/beta1:

$ git checkout -b bugfix/somefeature
Switched to a new branch 'bugfix/somefeature'

So far so good, right? Well, show me local branches again:

$ git branch
  BUGFIX/somefeature

The questions:

  • Why did the bugfix prefix of my branch get capitalized as BUGFIX?
  • Related, why is that not marked with an asterisk as my current branch?

I'm using git version 1.8.1.5 via Homebrew on OS X 10.8.2, and this happens with or without my pretty tame ~/.gitconfig in place. This happens for seemingly every bugfix/... branch.

Collin Allen
  • 4,449
  • 3
  • 37
  • 52

4 Answers4

146

Branches are stored as files within the .git directory. A single branch is a single file containing the hash to the commit object the branch points to.

So, as you maybe guess, when creating a branch foo/bar this will correspond to a directory with a file. So Git will create a folder foo with a file bar which then points to the commit.

This means when you add another branch foo/baz it will create a file baz and add that to the folder.

Now branch names are case insensitive for case insensitive file systems. This means that FOO/bar and foo/bar are the same. But the actual internal name is taken from the original folder and file name. So when the folder for your bugfix branch category is written in upper case, then the branches are recognized with an upper case BUGFIX.

To fix this, just go into .git/refs/heads and change the folder name to the way you like.

poke
  • 369,085
  • 72
  • 557
  • 602
  • 5
    Branch names are **not** case insensitive by their nature. That only happens when stored as files on a case-insensitive file system as is used by default in OS X. And branches aren't necessarily stored as a file; they could also be stored in the `.git/packed-refs` file, although that would be unusual and certainly wouldn't be the case for a newly created branch. – qqx Mar 12 '13 at 21:16
  • This was it! Inside `.git/refs/heads`, there was a `BUGFIX` directory. After removing that, I'm now able to checkout `bugfix/example` and git displays everything as I expected it to. I must have made a caps-lock typo once in the past while creating a bugfix, and it just waited until now to bite me. – Collin Allen Mar 13 '13 at 20:55
  • 2
    DANGERRRRR!!!!! This can lead to some serious problems! If for example you do git checkout mastER when you push the copitolization will be reflected in the repository (being a weird branch) and not locally. This can lead to _very bad things_ – meawoppl Feb 25 '14 at 23:01
  • 1
    @meawoppl Still, if you have—for whatever reason—introduced capitalized branch names, this is the simplest way to fix it. Of course, ideally, you don’t even get there in the first place and just use lower-case names. – poke Feb 25 '14 at 23:03
  • I totally agree. I just wanted to make sure that people didn't do cap foolery casually. See also: http://stackoverflow.com/questions/13828066/how-do-i-solve-a-folder-capitalization-conflict-with-git-on-windows You stand to make some more points posting your solution there. – meawoppl Feb 25 '14 at 23:07
  • Is this really a solution? I'm running into this now when it's translating 'bugfix/name' to 'Bugfix/name', and failing to push to remove as a result. It only happens on 'bugfix' branches; if I change it to anything else 'feature/name' or 'foobar/name' this does not occur and I can push normally. – K.Niemczyk Jun 23 '17 at 13:02
  • @K.Niemczyk Whether this is a solution for you depends a bit on what exactly is causing your problem. Case (in)sensitivity for branch names is certainly a thing that *can* cause problems. – poke Jun 23 '17 at 13:05
  • This allowed me to push with a lowercase branch name as desired, however it led to the following error when I tried to merge with our development branch: fatal: Couldn't find remote ref –allow-unrelated-histories – vikzilla Jan 17 '18 at 19:24
24

Thanks for the answer, it helped me find the solution to my problem, but mine was a little different. In my case, the folder with the capitalized name was not in .git/refs/heads, but in .git/refs/remotes.

Some time, long ago, someone had created two remote folders that differed only by the capitalization of the first letter. The capitalized version had been abandoned; but my repo, being from before that time, still had the capitalized spelling.

So every time I tried to pull from the new folder, it would work, but git put the local branch into the capitalized folder locally. The symptom was that I couldn't pull new changes to that branch; I had to delete my local copy and check the remote out again, every time.

My fix was to change the spelling of the folder name in .git/refs/remotes, and the problem has been resolved.

drdwilcox
  • 3,833
  • 17
  • 19
  • This is my exact scenario with /Bugfix & /bugfix. This caused lots of hassle and confusion during time crunch. If you are using UI tools such as fork, just after changing /Bugfix in .git/refs/remotes simply restart and you should see remote branch under correct folder/branch name. By correct - i mean correct case. – Anush Shrestha May 10 '21 at 21:39
15

To fix this issue, you should follow what @poke said and to disable this I have used the local git commands which can switch the ignore case to false.

To identify this, you can check the ignorecase by running the below command.

git config --global --get core.ignorecase

this command will return true which indicates that git is ignoring cases. To fix this make it as false by below command.

git config --global core.ignorecase false

This will disable the ignorecase in git. Hope this will fix this issue. Make sure you are not working on multi language projects, this setting might require true in that case.

Abhijeet Kamble
  • 3,131
  • 2
  • 30
  • 36
0

Here is the simple solution:

  • delete all your local branches
  • invalidate cache and restart your
    android studio
  • create new branches and it will not any more
    capitalize the first letter
junior
  • 45
  • 1
  • 11