Because of github changing the default branch from master to main all of my pushes end up in a separate branch instead of the main one and I can't change the default. When I start a program and make my first push, git tells me main doesn't exist and I always have to push to master instead.
Asked
Active
Viewed 2.9k times
24
-
Look at this [GitHub](https://docs.github.com/en/github/administering-a-repository/changing-the-default-branch)-Doc. – SwissCodeMen May 15 '21 at 05:11
-
I'm having this issue with Gitea – Zach May 26 '23 at 17:55
2 Answers
49
Following the FAQ article "How to Rename the master branch to main in Git", and the GitHub documentation itself, you can:
- rename your local branch from master to main:
git branch -m master main
- push to main:
git push -u origin main
- update your default branch on GitHub side:
- Then delete the remote master branch:
git push origin --delete master
Finally, as I documented in "How can I create a Git repository with the default branch name other than "master
"?", don't forget a:
git config --global init.defaultBranch main
(See commit 32ba12d, with Git 2.28+, Q3 2020)
Your next new repositories will use the right branch name by default.

VonC
- 1,262,500
- 529
- 4,410
- 5,250
14
Another way to change your default branch in your local machine, as pointed here, is to edit your ~/.gitconfig file and add or edit the following lines:
[init]
defaultBranch = main
I prefer this option because I've already had a bunch of configurations in my ~/.gitconfig file, so for me is better to lock it before and check whether the wanted configuration exists or not and if yes how it's set.

Gabriel Braico Dornas
- 439
- 3
- 11
-
4
-
@cynicaljoy Indeed it's the same, but still people could prefer this way of editing – Fee Jul 10 '23 at 12:02