Git branches seem to be case insensitive

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 you need to 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.

Recent posts View all

Talk CSS

FrontEnders - Web Performance

Sharing some of my thoughts on a FrontEnders meetup on the topic of Web Performance


Tips for how to ask for time off to attend conferences

Asking for time off to attend a conference can be nerve-racking, these tips will get you closer to attending the conferences you're interested in.