将旧模式master
改为main
是很常见的。这可以很容易地远程完成(GitHub提供了一个图形化的方式来做到这一点),但是…如何处理工作副本?
-
重命名本地分支:
git branch -m master main
-
改变跟踪分支
git fetch -p origin git branch -u origin/main main
-
更改本地主分支
git remote set-head origin -a
-
可选,删除主分支,本地和远程:
git branch -D master git push origin :master
更新
- 在步骤2中增加了
-p
参数,感谢@torek。 - 添加可选步骤以删除主分支
我不得不使用
git branch -u origin/**master** main
代替
git branch -u origin/main main