Git报错'fatal: The current branch master has no upstream branch'解决方法

在使用Git推送代码到远程仓库时,你可能会遇到如下错误信息:

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'.

这个错误意味着你当前的分支没有设置上游分支,导致Git无法确定要将你的代码推送到远程仓库的哪个分支。

以下是解决该错误的步骤:

1. 设置上游分支
执行以下命令将当前分支与远程仓库的master分支关联起来:

git push --set-upstream origin master
* `origin`: 远程仓库的名称,通常默认为'origin'。
* `master`:  远程仓库的分支名称,这里以'master'分支为例,你可以替换为你想要推送的目标分支。

2. 自动设置上游分支(可选)

如果你希望在将来创建新分支时自动设置上游分支,可以执行以下命令:

git config --global push.autoSetupRemote true

这将在你的全局Git配置中设置push.autoSetupRemote选项为true,从而实现自动设置上游分支的功能。

执行完以上步骤后,你就可以使用git push命令将代码推送到远程仓库了。

Git报错fatal: The current branch master has no upstream branch解决方法

原文地址: https://www.cveoy.top/t/topic/fBCu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录