Skip to content

Option 1 — for a local repo only

Rename the local branch:

git branch -m master main

Update your default push upstream (if desired):

git push -u origin main

Delete the old remote ref (optional if remote still has master):

git push origin --delete master

Option 2 — if you need to update an existing remote (recommended safe sequence)

Create and push main from master:

git checkout master
git branch -m main
git push -u origin main

Change the default branch on the remote hosting service (GitHub/GitLab/Bitbucket) to "main" via repository settings.
Remove remote master:

git push origin --delete master

Have collaborators update their clones:

git fetch origin
git branch -m master main        # if they still have master locally
git branch -u origin/main main
git remote set-head origin -a

Notes and tips

If you can't change settings (no web UI), ensure the remote's HEAD points to main:

git remote set-head origin main

For CI or other tooling, update any references to "master" (branch protection, pipelines, deploy configs).
For an entirely new repo you can initialize with main:

git init -b main

Related search suggestions will be provided.

how to set git remote

To add or change a Git remote, use these commands.

Add a new remote named “origin”:

git remote add origin

List remotes:

git remote -v

Change an existing remote URL:

git remote set-url origin

Remove a remote:

git remote remove origin

Push a branch to that remote and set upstream:

git push -u origin

Fetch and update remote HEAD:

git fetch origin git remote set-head origin -a

how do we force the first branch to be main? git init main??

To make the initial branch named main when creating a new repo, use:

Git >= 2.28 (preferred): set a global default then git init

git config --global init.defaultBranch main
git init    # creates main

One-off (any Git version):

git init
git checkout -b main

Directly specify branch at init (Git >= 2.28 supports -b):

git init -b main

For a single commit right away:

git init -b main echo “# Project” > README.md git add README.md git commit -m “Initial commit”