当前位置:   article > 正文

git远程连接推送代码报错 fatal: The current branch master has no upstream branch.

fatal: the current branch master has no upstream branch. to push the current

报错信息:

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啦~!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/416111?site
推荐阅读
相关标签
  

闽ICP备14008679号