Github直接push到main

标签 git github git-branch git-push git-remote

随着最近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/

相关文章:

javascript - GitHub API - 查找存储库使用的语言

git - github是否在历史记录中保留已删除的远程分支?如果是这样,这些可以恢复吗?

git - 在 Git 中跨分支共享文件

gitignore 文件夹中的所有文件但保留文件夹结构

git - 如何查找哪个 github 存储库正在使用 LFS

java - Jgit中 'pull'命令的使用

linux - 如何在不使用git命令的情况下进行推送

git - Github 和 Kiln 之间的自动同步

github - Dependabot 无法创建拉取请求,因为一个或多个其他依赖项需要与此更新不兼容的版本

git - 移动分支,使其从 git 中的 master 分支出来