git - 错误 : src refspec does not match any

标签 git github

我和几个 friend 在 GitLab 有个项目,当然有 master 分支,还有一些其他的。当我克隆存储库时,我还使用命令 git remote add upstream ... 创建了一个上游。

然后,我发布了 git fetch upstream。接着是 git checkout upstream/test1。现在,如果我输入 git branch -a,我会得到如下输出:

* (HEAD detached at upstream/test1)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/upstream/test1
  remotes/upstream/master

这一切都很好,但后来我对我的 upstream/test1 分支中的代码做了一些更改,我想将它们推送到 origin/test1 存储库,我在标题上收到错误消息。请注意,我按照以下步骤进行推送:

git add .
git commit -m "Sample message"
git push -u origin test1

如果我发出 git show-ref,我会得到以下输出:

refs/heads/master
refs/remotes/origin/HEAD
refs/remotes/origin/master
refs/remotes/upstream/test1
refs/remotes/upstream/master

我检查了以下 questions ,但没有发现它有帮助。有什么解决办法吗?

最佳答案

您似乎没有名为 test1 的本地分支。您有一个名为 test1remote 分支与您的 upstream 远程关联。

您不应该直接编辑 upstream/test1 分支。事实上,尝试检查它应该会产生警告:

$ git checkout upstream/test1

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

您应该首先检查跟踪远程分支的本地分支,它应该看起来像这样:

$ git checkout test1
Branch test1 set up to track remote branch test1 from upstream by rebasing.
Switched to a new branch 'test1'

完成此操作后,未修饰的 git push 将推送到 upstream 远程,而 git push origin test1 将推送到您的 origin 远程。在此处添加 -u 标志将切换跟踪分支,这样您的分支将跟踪 origin/test1 而不是跟踪 upstream/test1,因此 future 的 git pullgit push 操作将默认引用该远程分支 (origin/test1)。

关于git - 错误 : src refspec does not match any,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40202284/

相关文章:

git - 避免将 master merge 到开发分支

linux - "nothing to commit (working directory clean)"添加文件夹时

scala - 如何在 "sbt new"中指定一个分支?

jenkins - 如何在 Jenkins 中使用可嵌入的构建状态插件获取分支特定的构建状态

GitHub:如何重命名下载的 Zip 文件中的文件夹?

git - 从另一台计算机撤消 git push

git - 无法从 ubuntu 中的 bitbucket 克隆 git 存储库

git - 在 git 中提交消息前缀

git - 如何访问 TFS 中 PR 的更改目标分支

ruby-on-rails - Github 直接到 heroku