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
To https://github.com/your/project
 ! [remote rejected] master (refusing to delete the current branch: refs/heads/master)
error: failed to push some refs to 'https://github.com/your/project'

Switch default branch master to main at https://github.com/your/project

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
  remotes/origin/main

❯ git branch -l
* main

❯ git branch -r
  origin/main

 

■ 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おすすめツール