简体   繁体   English

git 如何更改我所做的一切的默认分支?

[英]git how to change default branch for everything I do?

Because of github changing the default branch from master to main all of my pushes end up in a separate branch instead of the main one and I can't change the default.由于 github 将默认分支从主分支更改为主分支,我所有的推送最终都在一个单独的分支而不是主分支中,我无法更改默认分支。 When I start a program and make my first push, git tells me main doesn't exist and I always have to push to master instead.当我启动一个程序并进行第一次推送时,git 告诉我 main 不存在,我总是必须推送到 master 。

Following the FAQ article " How to Rename the master branch to main in Git ", and the GitHub documentation itself , you can:按照常见问题解答文章“ 如何在 Git 中将主分支重命名为主分支”和GitHub 文档本身,您可以:

  • rename your local branch from master to main: git branch -m master main将本地分支从 master 重命名为 main: git branch -m master main
  • push to main: git push -u origin main推送到主: git push -u origin main
  • update your default branch on GitHub side:更新 GitHub 端的默认分支:
    在此处输入图像描述
  • Then delete the remote master branch: git push origin --delete master然后删除远程master分支: git push origin --delete master

Finally, as I documented in " How can I create a Git repository with the default branch name other than " master "? ", don't forget a:最后,正如我在“如何使用除“ master ”之外的默认分支名称创建 Git 存储库中所记录的那样,不要忘记:

git config --global init.defaultBranch main

(See commit 32ba12d , with Git 2.28+, Q3 2020) (参见提交 32ba12d ,Git 2.28+,2020 年第三季度)

Your next new repositories will use the right branch name by default.默认情况下,您的下一个新存储库将使用正确的分支名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM