How to rename the git "master" branch to "main"
I have recently published two articles, How to get started with Git and GitHub in your windows machine and How to import your company's private repository from Bitbucket into GitHub, and I remembered that GitHub, the Microsoft acquired source code hosting application, will be renaming its default repository branch master to main by October 2020.
The reason for renaming is to remove references to slavery and replace it with a more inclusive term. Using master in GitHub does not mean that they refer to slavery, but it is the origin of the term master that is the concern.
This means any repository created from October 1, 2020, will automatically use main as the default branch and NOT master.
However, those repositories created before the above date will have the same default branch, and this change will not affect them.
If you think the change by GitHub is likely to affect your workflow, you can dictate your default branches from your GitHub settings;-
- For user repositories use this link (you must be logged in) - https://github.com/settings/repositories
- For organizations use this link: https://github.com/organizations/<YOUR-ORGANIZATION HERE>/settings/repository-defaults. If you do not know how to create a GitHub organization, please checkout this article, How to import your company's private repository from Bitbucket into GitHub.
- For enter enterprises use this link - https://github.com/enterprises/<YOUR-ENTERPRISE HERE>/settings/member_privileges
See screenshot below
The bad or good news is that by the end of the year 2020, all existing repositories still using master as their default branch will be changed to main.
Before that is done, you need to do it yourself to avoid disruption on your git workflow, in case GitHub's automated tools make a mistake. You can checkout this article if you do not know what git workflow is, How to get started with Git and GitHub in your windows machine.
Proceed as follows;-
step 1: Rename old branch,
master to new branch,
main using the
git branch -m master main
step 2: Update remote repository using
-u option to add upstream (tracking) reference.
git push -u origin main
step 3: Login to your GitHub account and change your default branch to main. See the video below.
step 4: Now you can delete the master branch, in the remote repository
git push origin --delete master
I hope you enjoyed converting your repositories default branch form master to main.
Now you are inclusive :)