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

Change Git's Default Branch From Master

lukeocodes profile image Luke Oliff ・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.

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

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 Init Doesn't Let You Name a Default Branch

This change is a little hackier.

Modify your ~/.gitconfig (or ~/.config/git/config) and add this to the file.

# ~/.config/git/template/
[init]
  templateDir = ~/.config/git/template/

Create (or add to) the ~/.config/git/template/ directory a file named HEAD. Add to this line to the ~/.config/git/template/HEAD file.

ref: refs/heads/main

Now when you git init you won't have master, only main.

I Don't Want to Hack My Git Config

Scott shared an alias for git new to use instead of git init.

git config --global alias.new '!git init && git symbolic-ref HEAD refs/heads/main'

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.

Posted on by:

lukeocodes profile

Luke Oliff

@lukeocodes

60% water. Language champion. JAMStack's biggest fan.

Discussion

markdown guide
 

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