Defend your master branch against Rails generator

← Back

When you generate new Ruby on Rails application, the generator also inits a git repository for you. However, someone thought that it would be better not to leave the choice of the default git branch solely up to the users. So instead of generating whatever the default branch in git is, Rails now force you into a branch named main, even though you haven’t opted for it! Ruby on Rails team (and namely jayqui who filed the “bug” report and prateekkish who implemented the current misbehaviour) now force me to take action where none should have been required since I’m happy with how git behaves. To quote rafaelfranca:

This means that the behavior of rails new will be different from git init, but I see no problem on that.


Rant over. Let’s do it for once and for all:

git config --global init.defaultBranch master

Update: I’ve opened a pull request that would print a warning about the misbehaviour and information how to fix it. Rafaelfranca just closed it. No comment.

Tagged with: Ruby on Rails

Written: 2022-03-14