Posted 2020-10-08 with tags Github, git, version control

The Problem

If you encounter the following error on a recently created github project when trying to pull from the default branch:

fatal: Couldn't find remote ref master

it's probably because you have tried to use the old racist command:

git pull origin master

The default git branch name master has recently been found to be racist, so it's been changed to default to main instead.

So instead of pulling from the master branch, moving forward we'll pull from the default main branch:

git pull origin main

If you are running into this error in any part of your software infrastructure, or suspect this change of github default branch name is causing an issue in your application, please get in touch and we'll help you solve the issue.

How to Fix Existing Repos

If you'd like to update any existing repos to use main as the new default branch name, just follow these steps:

Step 1 - Rename Local Branch

git branch -m master main

Step 2 - Rename Remote Branch

git checkout main
git push -u origin main

Step 3 - Delete 'master' Remote Branch

git push origin --delete master

If you receive an error you main need to go into the web UI for your git host (Github for instance) and find the setting for 'default branch' and switch it to main before deleting the old master branch.

Step 4 - Tell Others to Update Their Local Repos

They'll just need to run the following in their local repos:

# Switch to "master" branch
git checkout master

# Rename "master" branch to "main"
git branch -m master main

# Get latest commits and branches from remote
git fetch

# Remove existing connection with "master"
git branch --unset-upstream

# Create connection with new "main" branch
git branch -u origin/main

Et voilà!