Rename Git branch master to main

❯ git -v
git version 2.39.1


■ Delete local branch

git branch -d master


■ Rename local branch

git branch -m master main


■ Push the new branch, set local branch to track the new remote

git push -u origin main

git push --set-upstream origin main


■ Delete remote branch

git push origin :master

git push origin --delete master

I got this.

❯ git push origin :master
 ! [remote rejected] master (refusing to delete the current branch: refs/heads/master)
error: failed to push some refs to ''

Switch default branch master to main at

Rename Git branch master to main


■ Show status

❯ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean

❯ git branch -a
* main

❯ git branch -l
* main

❯ git branch -r


■ Conclusion

Repository default branch
Choose the default branch for your new personal repositories. You might want to change the default name due to different workflows, or because your integrations still require “master” as the default branch name. You can always change the default branch name on individual repositories.

👉 GitHub - Settings - Repositories hatena-bookmark

👉 Managing remote repositories - GitHub Docs hatena-bookmark

関連ワード:  AndroidAndroidStudioappleGitIDEAiOSJetBrainsKotlinおすすめツール