Renaming a shared repository's default branch moves the branch name that teammates, pull requests, automation, and fresh clones expect to use. Treat the change as a short migration window, not just a local git branch -m command, so old and new names do not both receive work.
The local rename keeps the same commit history and branch reflog, then the new branch name is pushed and tracked on origin. The remote default branch is a separate setting on the Git host, or the HEAD symbolic reference on a self-managed bare repository, and it must point at the new branch before the old branch is removed.
Default-branch renames can break rules, CI/CD triggers, deploy jobs, bookmarks, and scripts that still name master. Check those references before deletion, and ask collaborators to retarget existing clones after the remote default branch changes.
Related: Rename a Git branch
Related: Change the default branch for new Git repositories
Related: Set upstream tracking for a Git branch
Related: Delete a remote Git branch
$ git branch --show-current master
If another branch is active, switch to the old default branch before renaming it.
$ git fetch origin
$ git status -sb ## master...origin/master
If status shows local commits ahead of or behind origin/master, resolve that difference before renaming so the old and new default branch names point at the intended commit.
$ git branch -m master main
Git normally prints no output when the branch rename succeeds.
$ git push -u origin main To git@example.net:team/project.git * [new branch] main -> main branch 'main' set up to track 'origin/main'.
$ git --git-dir=/srv/git/project.git symbolic-ref HEAD refs/heads/main
Hosted repositories such as GitHub and GitLab expose this as a repository default-branch setting or API value. Change that setting to main instead of running the bare-repository command.
$ git fetch origin
$ git remote set-head origin -a 'origin/HEAD' has changed from 'master' and now points to 'main'
$ git ls-remote --symref origin HEAD ref: refs/heads/main HEAD 7539b146757c3b2902e0a8d4f51070dc2d3b3a5b HEAD
$ git branch -m master main
Skip this command in a clone that already renamed master to main during the maintainer migration.
$ git fetch origin
$ git branch -u origin/main main branch 'main' set up to track 'origin/main'.
$ git remote set-head origin -a 'origin/HEAD' has changed from 'master' and now points to 'main'
$ git push origin --delete master To git@example.net:team/project.git - [deleted] master
If the host rejects deletion, the old branch may still be the default branch, protected by policy, or referenced by an integration that must be changed first.
$ git branch -r origin/HEAD -> origin/main origin/main
Related: Prune stale remote branches in Git
$ git status -sb ## main...origin/main