Skip to content

Instantly share code, notes, and snippets.

@niko-dunixi
Last active March 21, 2021 23:39
Show Gist options
  • Save niko-dunixi/a6752ed106620b59ea003f34770040a1 to your computer and use it in GitHub Desktop.
Save niko-dunixi/a6752ed106620b59ea003f34770040a1 to your computer and use it in GitHub Desktop.

How to change git's default branch

Ensure git is at least version 2.28.0

You need a recent enough version of git. If you're on ubuntu/debian, this will get the most recent stable version.

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update

Note: If you can't install these on a vanilla system (EG: a clean docker container) it's probably because you need the following packages installed first:

  • software-properties-common
    • This is for the add-apt-repository command
  • gnupg2
    • This is for the more modern gpg command that add-apt-repository will call on your behalf to install Git's trusted GPG repo key

Global configuration for new repos

git config --global init.defaultBranch main

To update existing repos

git branch -m master main
git push origin :master main
git branch --set-upstream-to=origin/main main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment