loading...
Play Button Pause Button

Changing the default branch name on GitHub

nocnica profile image Nočnica Fee ・1 min read

While the tech industry struggles to address injustice in our society, a small step you can take today is to remove the use of "Master/Slave" terminology from your tools.

git still calls the default branch of repositories 'master', a holdover from BitKeeper, which had both master and slave branches.

It's a bit surprising that this is a bit difficult to stop naming branches 'master'! While you can create a copy of 'master' with a new name, you can't delete 'master' without using the GitHub web interface.

From the cli you can move your branch to a copy (named 'main' in this example) with

git branch -m master main

then push it to GitHub with

git push origin main

But master will still be on GitHub, and you can't delete it since it's the default branch! You'll need to go to github.com and go to Settings>Branches to change the default. Only then can you delete the branch from github with

git push origin --delete master

So how do we make sure that all future repositories we create don't use 'master'?

Thankfully André Arko wrote a useful post on the subject

function git() {
  command git "$@"
  if [[ "$1" == "init" && "$@" != *"--help"* ]]; then
    git symbolic-ref HEAD refs/heads/main
  fi
}

With this, every time we initialize a repository with git init we will immediate move it to use the branch name 'main'

Posted on by:

nocnica profile

Nočnica Fee

@nocnica

Actually the pug from Dune (1984)

Discussion

markdown guide
 

Thanks so much! I'm new to coding, but those terms have made me feel icky. Thank you, thank you!

 

Very nice! I've been going through my repositories updating them (I'll probably post something about it on Wednesday or Thursday, myself), but something that hadn't occurred to me was deleting the original branch.

 

Awesome! I look forward to reading it.

 

Thanks for this! I actually forgot you can change the default branch on github 😅😅

 

I hope the workshop goes well today @Nočnica! This is definitely an important topic.

 

With the latest git version 2.28 you can set the default branch name globally with this command:

git config --global init.defaultBranch main

Git v2.28 highlights

 

Thank you! I need to update this post :)

 

How do you add the git function to git itself so that it's run whenever we init a repo?

 

I do not think there’s a good way to do that, though anyone who clones a repository so initiated will have the same branch naming scheme.

Thankfully GitHub is looking at changing default naming soon :)

 
 
Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

It's horrible that the politics have came here, to IT. Who's next victim of SJW and "political correctness" going to be? Is it Blacklists? man pages? Servers? How did we even come to this?..

 

This is a highly disingenuous comment Bohdan.

 

Too aggressive on his part and the original issue is beyond politics, I agree.

But there is a point in there. Git certainly isn't the only thing using the master/slave terminology. There's a lot of refactoring (perhaps total rebuilding) to be done worldwide if we want to be consistent about this.

Btw, for transparency purposes stackoverflow clearly shows the number of downvotes on answers that were non-constructive. As far as I can tell the invisible hand of the "community" faded away that comment, although that comment has above average hearts.

While it may be poorly worded, the fact that is has nearly double the amount of hearts would suggest that it is a shared sentiment.