Error: 无法将某些引用推送到'https://github.com/'

34

这是我的仓库 https://github.com/kiotie32/artbit-text.git 当我执行

$ git push -u origin master
remote: Repository not found.
fatal: repository 'https://github.com/kiotie32/arbit-text.git/' not found

我正在使用Windows 10电脑。我已经配置了ssh密钥以便在这台笔记本电脑上使用。 我执行ls命令,可以看到

 MINGW64 ~/.ssh
$ ls
kiotie32_rsa  kiotie32_rsa.pub  known_hosts

我阅读了此帖子上给出的所有答案。 我更改了存储在Windows凭据管理器中的密码。
我检查git remote -v | head -n1 | awk '{print $2}' | sed 's/.*\///' | sed 's/\.git//' 我得到以下输出arbit-text 我更改了存储在Windows凭据管理器中的密码,可能是存储了旧密码。
我没有收到任何弹出窗口要求输入用户名和密码。(已配置ssh密钥,但不确定是否适用于我存储在git bash中的Windows 10环境。)
现在我这样做:
$ git remote add origin https://github.com/kiotie32/arbit-text.git
fatal: remote origin already exists.

那我就这么做

$ git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/kotie32/arbit-text.git'

所以我不明白为什么会出现这个错误。

我尝试了这里的解决方案https://dev59.com/vm855IYBdhLWcg3wuG0M#7572252,第一个答案是执行以下命令:
git commit -m "initial master"
然后我收到以下错误:
$ git push origin master remote: Repository not found. fatal: repository 'github.com/kotie32/arbit-text.git' not found
然后我按照评论中的方式尝试了以下命令:
git add -all,然后我执行了以下命令:
$ git push origin master remote: Repository not found. fatal: repository 'https://github.com/kotie32/arbit-text.git/' not found

然后我尝试了另一个答案https://dev59.com/vm855IYBdhLWcg3wuG0M#4183856,执行以下命令:
$ git show-ref 79d1730e9aa78f68a11ec4de6a0e8d6b66f17afb refs/heads/master
然后我执行了以下命令:
$ git push origin HEAD:master remote: Repository not found. fatal: repository 'https://github.com/kotie32/arbit-text.git/' not found

我注意到上面网址中最后一个错误中的拼写“kotie32”是错误的,它应该是 kiotie32 检查了.git文件夹中的config文件 然后我看到以下内容

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = https://github.com/kiotie32/arbit-text.git
        fetch = +refs/heads/*:refs/remotes/origin/*

所以这里的URL是正确的,拼写是kiotie32,这是正确的。

好的,我现在注意到已经形成了两个目录。 项目文件夹/.git/.git<项目文件夹>/.git的配置文件有错误的URL, 而内部的那个,即<项目文件夹>/.git/.git有正确的URL。

我更改了<项目文件夹>/.git的配置文件并删除了子目录.git/.git, 新的配置文件为

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = https://github.com/kiotie32/arbit-text.git
        fetch = +refs/heads/*:refs/remotes/origin/*

{{然后我再次执行}}
$ git push -u origin master
remote: Repository not found.
fatal: repository 'https://github.com/kiotie32/arbit-text.git/' not found

然后我做了{{某些事情}}。
$ git remote set-url origin https://github.com/kiotie32/artbit-text.git

那么现在我可以推送到主分支。


https://stackoverflow.com/search?q=%5Bgit%5D+error%3A+src+refspec+master+does+not+match+any - phd
这个回答解决了你的问题吗?git错误:无法推送一些引用 - Enlico
我现在已经删除了所有内容,并从头开始重新做了一遍。我不记得在我发布问题时出现了什么错误。目前我的笔记本电脑上的事情都正常运行。 - koeradoera
也许没有 master 分支,测试 main :D - hamid Mahmoodi
显示剩余2条评论
23个回答

44

我曾经遇到同样的问题,但是这个命令解决了它。

替换:

git push -u origin master

使用以下命令:

git push -u origin main

或者
git push -f origin main

1
非常感谢。这个答案解决了问题。 - 4xMafole
1
但是分支有变化怎么办?我想直接推送到主分支。 - Eklavya Chandra
1
@EklavyaChandra 我建议阅读这篇文章 https://stevenmortimer.com/5-steps-to-change-github-default-branch-from-master-to-main/ - Amitesh mani tiwari
谢谢。答案已标记为绿色。 - Adil Shinwari

41

试一下以下命令:

git push origin master --force

3
不,那不是问题所在。当你回答我的问题时,我已经在2020年3月12日发布了问题,而你的回答是在2020年5月19日,我在提问中已经给出了解决方案。问题是我有两个.git文件夹,一个文件夹在另一个git文件夹内部,并且远程仓库链接错误,所以我将它们删除,然后从头开始重新做了所有事情。然后它就起作用了。 - koeradoera

18

请检查您是否尝试在提交之前推送更改,请尝试提交您的更改。

git commit -m "my commit"

或者输入git branch查看是否设置了远程URL,如果没有显示任何内容,则添加远程源URL git remote add origin https://github.com/username/projectname.git。然后尝试git push origin master


6

这对我很有帮助。

git push origin master:main

master 是我的本地分支,而 main 是我的远程分支。我认为这是由于 Github 将 master 重命名为 main 所导致的。


5
  1. 尝试执行提交命令。

git commit -m "第一次提交"

  1. 将所有文件加入暂存区或选择特定的文件。

git add .

  1. 检查文件的状态。

git status

  1. 将代码推送到你的代码库。

git push origin main(或者是你主分支的名称)。


4

这对我的情况起作用了。

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

请输入您的邮件地址和 Github 用户名


由于我有多个git账户在使用,所以我没有包含--global标志,但这对我解决了问题。 - Zach Saucier
它对我有效,但我不知道为什么,因为我已经设置好了。 - Marco Mesen

3

在运行git push命令时,通常会遇到此错误消息。执行以下命令:

git add --all

然后:

git push -u origin main

2

还有一件事(以防这对未来的某些人有所帮助):你必须要有一个提交才能推送。


2

实际上这是由于更改Github账户凭据导致的

例如,您的gitbash过去与'A'账户存储库同步,而现在您正在尝试从'B'账户存储库进行推送或拉取。这意味着您正在尝试推送或拉取属于其他账户而不是旧账户的存储库。

此时会出现此异常(错误'无法将某些引用推送到'https://github.com/ ')。

实际上,操作系统(Linux或Windows)将您的帐户身份验证存储在旧帐户的凭据管理器中。当您从帐户'B' Repo(新帐户)推送或拉取时,Gitbash会使用存储在OS凭据管理器中的帐户'A'(旧帐户)的凭据对您的帐户'B'(新帐户)进行身份验证,然后引发此错误。

解决方案

  1. 在Windows搜索栏中键入“凭据管理器”

如何打开凭据管理器

2. 打开凭据管理器 3. 单击Windows凭据

如何打开Windows凭据管理器

  1. “单击git:https://GitHub.com”

如何删除Github凭据

  1. 删除凭据后,您将被要求提供新帐户详细信息,因为它对您进行身份验证,您的代码将被推送或拉取。

  2. 如果您无法推送或拉取,则设置您的电子邮件和姓名,然后推送。

git config  user.email 'xxxx@gmail.com'
git config user.name 'xxxxx'

再次推送

git push -u origin branch_name

感谢您的询问。

2
git push -u origin HEAD:master

4
目前你的回答表达不清楚,请编辑并添加更多细节,以帮助他人理解如何回答问题。你可以在帮助中心中找到有关撰写好回答的更多信息。 - Community
2
感谢您提供这段代码片段,这可能会提供一些有限的即时帮助。适当的解释将极大地提高其长期价值,因为它可以展示为什么这是一个好的解决方案,并使其对未来有类似问题的读者更有用。请[编辑]您的答案以添加一些解释,包括您所做出的假设。 - helvete
虽然这段代码可能回答了问题,但提供有关它如何以及/或为什么解决问题的附加上下文将改善答案的长期价值。您可以在帮助中心找到有关编写良好答案的更多信息:https://stackoverflow.com/help/how-to-answer。祝你好运! - nima

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