报错信息:

fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

To have this happen automatically for branches without a tracking upstream, see 'push.autoSetupRemote' in 'git help config'.

解决方案:

报错原因:当前的分支 "master" 没有与远程分支关联(也就是没有上游分支)。通常情况下,你可以使用 git push --set-upstream origin master 命令来将当前分支与远程分支建立关联并推送代码。

1. 首先,运行以下命令将当前分支 "master" 与远程分支关联并推送代码:

git push --set-upstream origin master

这将设置 "origin/master" 作为 "master" 分支的上游分支,之后你可以简单地运行 git push 以将更改推送到远程的 "master" 分支。

2. 如果你希望在将来的推送中不必再次使用 --set-upstream 标志,可以配置 Git 以自动设置上游分支。你可以运行以下命令:

git config --global push.default current

这会将默认的推送行为设置为 "simple",这意味着 Git 会尝试自动设置上游分支,以便将来的推送可以直接运行 git push。

完成上述步骤后,你应该能够成功地将更改推送到远程 "master" 分支,而无需再次输入 --set-upstream 标志。

后面就可以直接git push啦~!

相关链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。