如何将git中的当前分支从master更改为main

  • 本文关键字:master main 分支 git git
  • 更新时间 :
  • 英文 :


将旧模式master改为main是很常见的。这可以很容易地远程完成(GitHub提供了一个图形化的方式来做到这一点),但是…如何处理工作副本?

  1. 重命名本地分支:

    git branch -m master main
    
  2. 改变跟踪分支

    git fetch -p origin
    git branch -u origin/main main
    
  3. 更改本地主分支

    git remote set-head origin -a
    
  4. 可选,删除主分支,本地和远程:

    git branch -D master
    git push origin :master
    

更新

  • 在步骤2中增加了-p参数,感谢@torek。
  • 添加可选步骤以删除主分支

我不得不使用

git branch -u origin/**master** main

代替

git branch -u origin/main main

最新更新