随着最近master
的变化至 main
在 Github 中,看来我需要先推送到 master
然后与 main
merge .当我尝试使用 --remote-upstream
推送时至 main
我收到一个错误:error: src refspec main does not match any
.
在带有 OMZ 的 iterm2 上,当我第一次运行时 git init
我看到master
在路径中。
如何直接推送到主而不是先推送到主?
最佳答案
如果我没记错的话,在 Git 版本 2.28.0 中,您可以使用命令 git init -b
为了设置您的默认分支。
例如,使用 main
创建一个新的存储库分支作为默认分支。
git init -b main
如果您想输入更长的名称:git init --initial-branch=main
您甚至可以全局设置它。git config --global init.defaultBranch main
作为替代方案,在创建新存储库时,您可以执行 git clone
到您的系统。默认分支将相应调整。关于
git init -b
命令,取自 Git 的文档:Use the specified name for the initial branch in the newly created repository. If not specified, fall back to the default name (currently master, but this is subject to change in the future; the name can be customized via the init.defaultBranch configuration variable).
阅读更多 here .
另一种选择,只需将默认分支名称保留为
master
在您的远程存储库中。
关于Github直接push到main,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66621725/