DEV Community

loading...
Cover image for Change Git's Default Branch From Master

Change Git's Default Branch From Master

lukeocodes profile image @lukeocodes πŸ•ΉπŸ‘¨β€πŸ’» ・Updated on ・2 min read

Scott covered this nicely with links to topics that show how master originated from BitKeeper. There is evidence to strongly suggest it does pertain to the outdated, oppressive and perverse master/slave metaphor, rather than master-copy.

Edited 17th October 2020 (a bit late, I know!), Git now lets you set a default branch for init, and GitHub now defaults to main.

But if you have an older repository, some of these steps remain relevant.

So, here are the steps I followed:

Move Master to Main

# maintain refs
git branch --move master main

# push to remote
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Change the Default on Remote

Now depending on your remote tool, this might differ.

GitHub

  1. Assuming you've pushed main from the steps above.
  2. Go to your Settings
  3. Go to the Branches section
  4. Change "Default branch" from master to main

GitHub change default branch from master to main

GitLab

  1. Assuming you've pushed main from the steps above.
  2. Go to your Settings
  3. Go to the Repository section
  4. Change "Default Branch" from master to main

GitLab change default branch from master to main

BitBucket

  1. Assuming you've pushed main from the steps above.
  2. Go to your Repository settings
  3. Go to the Repository details section
  4. Change "Main branch" from master to main

BitBucket change default branch from master to main

then...

  1. Go to the Branching model section
  2. Change "Development branch" from master to main

BitBucket change development branch from master to main

Git Now Lets You Name a Default Branch

Git Init Doesn't Let You Name a Default Branch

Edited 17th October 2020 Since git 2.28, you've been able to change your default branch using built-in git features.

git config --global init.defaultBranch main
Enter fullscreen mode Exit fullscreen mode

Summary

Sort of past the point about caring which side you fall on here. The evidence is there. Be your own teacher, make the world a better place.

Discussion (6)

Collapse
dnsmichi profile image
Michael Friedrich

git 2.28 now allows to set a default branch name: git config --global init.defaultBranch main :)

lwn.net/Articles/827174/
The name of the primary branch in existing repositories, and the
default name used for the first branch in newly created
repositories, is made configurable, so that we can eventually wean
ourselves off of the hardcoded 'master'.

Collapse
shvahabi profile image
Ψ΄Ψ§Ω‡Ψ―

For a repository-wise intended name we can use: git init --initial-branch=stable

Collapse
lukeocodes profile image
@lukeocodes πŸ•ΉπŸ‘¨β€πŸ’» Author

Oh, thanks Michael! I'll update the post!

Collapse
lukeocodes profile image
Forem Open with the Forem app