This is a short post explaining the current state of the default Git branch name in the Learn Enough tutorials and the Ruby on Rails Tutorial. If you reached this post from a tutorial ebook that uses the
masterbranch, you should download a free updated version, which has been changed to use
main. For more a detailed discussion of version control with Git, see Learn Enough Git to Be Dangerous.
The Git version control system is designed to help you track changes in projects. As part of this, Git allows you to create separate “branches” for particular sets of project changes, which can then be incorporated (or merged) back into the default branch.
Upon Git’s initial release in 2005, the default Git branch was called
master. Some developers, concerned about possible negative associations with this term, have advocated for using a different name for the default branch, such as
main.1 Most noably, in October 2020 developer platform GitHub announced that new repositories will use
main by default. In practice, this means that GitHub’s instructions for new repositories use
main instead of
master, including a command that changes the default branch name on the local repository (Figure 1).
As of this writing, Git itself still uses
master by default, but there are plans to change to
main in Git as well. Indeed, at this point most major Git organizations have changed or are planning to change to
main as the preferred default branch name. As part of this transition, more recent versions of Git have added an additional configuration parameter called
defaultBranch to specify the default branch name for new repositories.
Accordingly, the Learn Enough tutorial books (including the Ruby on Rails Tutorial) have been updated to use
main. In addition, while it is impractical to update all 55+ hours of Learn Enough screencast videos, a note has been added to the Learn Enough Git to Be Dangerous videos indicating that users should make the substitution
main in the screencasts.
Because Git used
master as the default branch name for the first 15+ years of its existence, there are a large number of existing Git repositories using that name for the primary branch, and there is a correspondingly large amount of documentation and third-party software that assumes this default branch name as well. As a result, making this
main substitution will be necessary for a long time to come, but luckily it’s not too difficult. Moreover, unexpected changes happen all the time in software development, so this is an excellent chance to apply one of Learn Enough’s core principles, technical sophistication. In the rest of this post, we’ll discuss a solution resulting from an application of this principle.
In order to apply the solution in this post, it’s important to use a version of Git that supports the
defaultBranch configuration parameter, which is included as of Git version 2.28.0. You can check your Git version at the command line as follows:
$ git --version git version 2.31.1 # should be at least 2.28.0
If the version number isn’t at least 2.28.0, you should update your installation of Git as described in Section 1.1: Installation and setup of Learn Enough Git to Be Dangerous. In particular, cloud IDE users can run the command in Listing 12 and macOS Homebrew users can run the command in Listing 2.
$ source <(curl -sL https://cdn.learnenough.com/upgrade_git)
$ brew upgrade git
Once the Git version has been verified (and, if necessary, updated) as in Section 1, we are ready to ensure that the default branch name is
main. The first step is to configure your local system by setting the global configuration parameter
main, as shown in Listing 3. This command needs to be run only once on each computer you use for software development.
$ git config --global init.defaultBranch main
The second step is to confirm that your default branch at GitHub is set to
main. You can do this as follows:
- Sign in to your GitHub account.
- Go to github.com/settings/repositories.
- Confirm that the default name appears as
- If it is not
main, change it to
mainin the text field and then click “Update”. The result should be as shown in Figure 2.
Note that the capabilities of Git and GitHub described above make it possible to use any branch name as the default. To use, e.g.,
default (or to revert to
master), simply replace
main with your preferred default branch name in Listing 3 and Figure 2.
masterin Git refers instead to the notion of a master recording. Lingering concerns remain, however, leading many developers to favor a change from
mainin any case.