错误:源参考规范master与任何内容都不匹配。

85

我尝试按照这篇帖子中提出的解决方法,但它没有起作用,我仍然收到错误信息:src refspec master does not match any。

这是我所做的: 按照这个解决方案。

// adding the file I created
$ git add .
$ git commit -m 'initial commit'
$ git push origin master
error: src refspec master does not match any.

当做:

$ git push origin HEAD:master
b40ffdf..a0d1423  HEAD -> master // looks promising

// adding a remote
$ git remote add devstage -f <another git>
$ git merge devstage/master -s recursive -X ours
$ git push -u devstage master
error: src refspec master does not match any.

更多信息:

$ git branch 
* origin

$ git show-ref
refs/heads/origin
refs/remotes/devstage/master
refs/remotes/origin/HEAD
refs/remotes/origin/devstage
refs/remotes/origin/master
refs/remotes/origin/origin

所以我肯定缺少refs/heads/master,但不知道如何创建它。

谢谢


你是如何创建你的代码库的?你创建了哪个文件? - Michael Ver
@MichaelVer:git克隆 https://<用户名称>@bitbucket.org/<我的代码库> - special0ne
2
最近Github将git push origin master更改为git push origin main - Vintage Coder
这是一个重复的问题 Git: Message https://dev59.com/vm855IYBdhLWcg3wuG0M - Vintage Coder
27个回答

0

这个错误也可能是由于本地分支名称不匹配导致的。 请确保您提供了正确的本地分支名称(检查拼写和大小写敏感性
我之前也遇到同样的错误,因为我的本地分支名是“validated”,尝试使用git push -f origin validate来推送更改,将其更新为git push -f origin validated后,问题解决了。

希望对您有所帮助。


0
对我来说,解决方法似乎是“git .”(将所有当前文件都暂存)。显然,在执行git init之后需要这样做? 我接着执行了“git reset”(取消暂存所有文件),然后继续使用完全相同的命令只暂存了几个文件,然后成功推送。
   git . 
   git reset

0

我也遇到了这个问题,后来发现Github正在尝试验证我的账户。因此,你需要运行以下2条命令:

git config --global user.email <your github email>
git config --global user.name <your github username>

0

顺便说一下,我遇到了同样的错误,但我认为它是由以下事件序列引起的:

  • 使用master分支创建了远程Git存储库。
  • 然后创建了本地克隆。
  • 然后修改了远程Git存储库,包括定义为默认分支的dev分支,并添加了对master分支的权限,以防止未经拉取请求进行更改。
  • 在本地克隆中发生了代码更新,准备推送到远程存储库。

然后,在尝试将更改从本地推送到远程时,收到错误“src refspec master does not match any”,或者在尝试推送到dev时,“src refspec dev does not match any”。

因为本地克隆中有待处理的更改,所以我不想炸掉它并刷新。 因此,通过将本地分支重命名为dev来解决了这个问题...

$ git branch -m dev

...然后正常推送git push origin dev,这次成功了,没有抛出上述错误。


0

我在使用一个新的代码库时遇到了这个错误 (error: src refspec master does not match any),当我尝试执行 git push origin master 时,因为 GitHub 将默认分支名称从 master 改为了 main

所以,git push origin main 对我来说是有效的。


-1

对于一个新的代码库,以下方法适用:

  1. 删除与git相关的文件
    rm -rf .git

  2. 重新提交
    git add . && git commit -m "你的提交信息"

  3. 添加git URL并再次尝试推送
    git remote add origin <你的git URL>

  4. 然后再次尝试推送
    git push -u origin master -f

  5. 成功!

由于这是一个新的代码库,所以删除并重新添加git不会有任何影响。


-1

我已经提交了更改并添加了所有文件,与远程仓库的源相同,但仍然一直出现错误。我的简单解决方案就是:

git push

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接