How to rename the default branch on GitHub

Roberto Gonzalez
2 min readJul 13, 2020

--

  1. 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

--

--

Roberto Gonzalez
Roberto Gonzalez

Written by Roberto Gonzalez

Quiero una vida sencilla, Largarme al campo, y huir de este lugar, Cultivar mis semillas, Ser dueño de mi tierra y de mi hogar, Sin gas, ni luz, ni jazz...

No responses yet