How to rename the default branch on GitHub
- Renaming the local
master
branch, based on the process described by Linuxize (2020).
- Checkout master:
$git checkout master
- Rename master:
$git branch -m main
- Push the new name, in this case
main
:
$git push origin -u main
2. Setting the new branch name as the default, you will need permissions:
A warning message will be shown with the legend: “Changing your default branch can have unintended consequences that can affect new pull requests and clones.” Do the update at your own risk.
3. Delete the master
remote branch:
$git push origin --delete master
Easy right?
Update (July/28):
Git just release Git 2.28, the update includes a configuration variable to set the default branch to something else than master
.
$git config --global init.defaultBranch main
This will make easier to have different default branch names from the beginning. As Blau, T. (2020) mentions, this configuration only affects new repositories, so this post is still useful as a reference for existing repositories.
Known issues
- GitHub pages only work with
master
branch.
References
- Linuxize. (2020, February 18). How To Rename a Local and Remote Git Branch. Retrieved from https://linuxize.com/post/how-to-rename-local-and-remote-git-branch/.
- Wouter, J. (2012, December 26). Deleting remote master branch, refused due to being current branch, answer. Retrieved from https://stackoverflow.com/a/14041409/799162.
- Blau, T. (2020, July 28). Highlights from Git 2.28. Retrieved from https://github.blog/2020-07-27-highlights-from-git-2-28/