Git Branch Name – Why is Git Capitalizing My Branch Name Prefix?

git

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.

Best Answer

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.

Related Question