Changing the default branch name on GitHub

Nočnica Mellifera - Jul 23 '20 - - Dev Community

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
}
Enter fullscreen mode Exit fullscreen mode

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

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player