Git branches seem to be case insensitive
A weird quirk with casing and Git and how to resolve it
Git branches appear to be case insensitive, which isn’t a problem in and of itself, but if you clone a remote branch from github like this:
git checkout -b my_new_branch /origin/My_New_Branch
Git will see your new branch as my_new_branch
* and when you pull it will check origin/My_New_Branch
which is totally correct and sane, but if you do a push it seems to want to push to a new branch in github called my_new_branch
which will get super confusing if multiple people need to access this branch.
The ideal fix for this is prevention - just don’t create a new local branch with a different name to your remote branch, but let’s say you do?
Creating a new branch with the correct case will not work because git is case insensitive and will see both my_new_branch
and My_New_Branch
as the same thing, instead rename your current branch using a middle step. Luckily like most things in git this is very straightforward;
git branch -m my_new_branch tmp_branch
(will rename your lowercase branch to tmp_branch)
git branch -m tmp_branch My_New_Branch
(will rename to your desired CamelCase branch!)
Now your pushes should go to the correct branch.
*Disclaimer - My_New_Branch is a terrible name for a branch, always be descriptive and imagine you are naming it for someone else who doesn’t know the project to read.