消息“src refspec master 与任何内容都不匹配”在 Git 中推送提交时
我克隆我的存储库:
git clone ssh://xxxxx/xx.git
但是在更改一些文件并添加
和提交
它们之后,我想将它们推送到服务器:
git add xxx.php
git commit -m "TEST"
git push origin master
但是我得到的错误是:
error: src refspec master does not match any.
error: failed to push some refs to 'ssh://xxxxx.com/project.git'
I clone my repository with:
git clone ssh://xxxxx/xx.git
But after I change some files and add
and commit
them, I want to push them to the server:
git add xxx.php
git commit -m "TEST"
git push origin master
But the error I get back is:
error: src refspec master does not match any.
error: failed to push some refs to 'ssh://xxxxx.com/project.git'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(30)
也许你只需要承诺。当我这样做时,我遇到了这个:
哎呀!从来没有犯过!
我所要做的就是:
成功!
Maybe you just need to commit. I ran into this when I did:
Oops! Never committed!
All I had to do was:
Success!
refs/heads/master
吗?git push origin HEAD:master< /code> 作为一个更独立于本地引用的解决方案。这明确表明您想要将本地引用
HEAD
推送到远程引用master
(请参阅 git-push refspec 文档)。git show-ref
to see what refs you have. Is there arefs/heads/master
?git push origin HEAD:master
as a more local-reference-independent solution. This explicitly states that you want to push the local refHEAD
to the remote refmaster
(see the git-push refspec documentation).删除本地计算机上的所有文件后,我也遇到了类似的错误,我必须清理存储库中的所有文件。
我的错误消息是这样的:
通过执行以下命令解决了这个问题:
I also had a similar error after deleting all files on my local computer, and I have to clean up all files in the repository.
My error message was something like this:
And it was solved by executing the following commands:
为此,您需要输入如下提交消息,然后推送代码:
成功推送到master。
For that you need to enter the commit message as follows and then push the code:
Successfully pushed to master.
对我来说,我必须确保公钥在服务器上正确配置(附加在〜/.ssh/authorized_keys中)和GitHub/Bitbucket (添加到我的GitHub 或 Bitbucket 上的 SSH 密钥) - 它们需要匹配。然后:
For me I had to make sure the public key is properly configured on the server (appended in ~/.ssh/authorized_keys) and in GitHub/Bitbucket (added to my SSH keys on GitHub or Bitbucket) - they need to match. Then:
在我仅使用一个空目录运行 git add 后,在一个全新的存储库中发生了这种情况。
一旦我添加了一个文件(例如
git add README.md
),那么git push
就工作得很好。This happened to me in a brand new repository after I ran
git add
with only an empty directory.As soon as I added a file (e.g. a
git add README.md
), thengit push
worked great.缺少或跳过
git add .
或git commit
可能会导致此错误:要修复它,请重新初始化并遵循正确的顺序:
Missing or skipping
git add .
orgit commit
may cause this error:To fix it, reinitialize and follow the proper sequence:
面临的问题
当我在 GitHub 上创建一个新存储库并将其与我拥有的客户端计算机中的 React 应用程序链接时,我遇到了同样的问题。
我使用了以下步骤:
问题之前使用的命令
我的错误
但正如你所看到的,我的错误是没有使用 git add . 命令。
我犯了这个错误,因为我已经有了 README.md 文件,并且 GitHub 在创建存储库时指导我们使用基本命令。
我的解决方案
我的解决方案是在
git init
命令之后使用git add .
。以相同的顺序使用以下命令集来解决该问题:
Problem faced
I had the same problem when I was creating a new repository on GitHub and linking it with my React app in the client computer I have.
I used the following steps:
Commands used before the problem
My mistake
But as you can see, my mistake was not using the
git add .
command.I did this mistake, because I already had the README.md file and GitHub instructs us with basic commands while creating the repository.
My solution
My solution is to use
git add .
after thegit init
command.Use the following set of commands in the same order to overcome the problem:
要修复此问题,请重新初始化并遵循正确的代码顺序:
To fix it, re-initialize and follow the proper code sequence:
当您位于特定分支并尝试推送尚不存在的另一个分支时,也会发生这种情况,例如:
This happens too when you are in a specific branch and try to push another branch that does not exist yet, like:
我遇到了同样的问题,我使用了
--allow-empty
:补充
这个问题的主要原因之一是一些Git服务器,例如BitBucket,没有他们的
master< /code> 分支在克隆新存储库时初始化。
I faced the same problem, and I used
--allow-empty
:Supplement
One of main reasons of this problem is that some Git servers, such as BitBucket, don't have their
master
branch initialized when a fresh repository is cloned.几天前我遇到了同样的问题。
如果您现在(2020 年)创建了一个新存储库,那么默认分支是 GitHub 上的main。
您现在可以在您的存储库分支中检查 GitHub。
您还可以通过运行命令来检查终端中的分支:
这就是为什么您需要运行
而不是
I faced the same issue some days ago.
If you created a new repository nowadays (2020) then the default branch is main on GitHub.
You can check on GitHub now in your repository branches.
And you can also check the branch in the terminal by running the command:
So that's why you need to run
instead of
确保您已先添加,然后提交/推送:
例如:
Make sure you've added first, and then commit/ push:
Like:
两种可能性:
1-您忘记包含
.gitignore
文件。以下是所需的所有步骤:
在远程创建一个空的 Git 存储库,
在本地创建 .gitignore
为您的项目创建文件。 GitHub 为您提供了示例列表
启动终端,然后在您的项目中执行以下操作命令:
2- 或者您正在尝试创建一个新的 GitHub 项目。
GitHub 将 master 替换为 main 作为默认分支名称。要解决该问题:
.git
文件夹(如果存在)在终端中:
Two possibilities:
1- Either you forgot to include the
.gitignore
file.Here are all the steps required:
Create an empty Git repository on remote,
On local, create the .gitignore
file for your project. GitHub gives you a list of examples here
Launch a terminal, and in your project do the following commands:
2- Or you are trying to create a new GitHub project.
GitHub replaced master with main as the default branch name. To resolve the issue:
.git
folder if it existsIn the terminal:
对我来说,以下工作是移动未跟踪的文件:
接下来,我遵循类似的步骤
然后,
最后但并非最不重要的:
当您执行此操作时,Windows 安全将弹出,询问您的用户名和密码。
For me,following worked to move untracked files:
Next, I followed similar steps
Then,
Last but not the least:
As you do this, Windows security will pop up asking for your username and password.
您可能忘记了
git init
命令之后的命令git add .
。You probably forgot the command
git add .
after thegit init
command.GitHub 2000-10-01 更新后,您应该使用 main 而不是 master。
这样做...
.git
文件git init< /code>
git add .
git commit -m"My first commit"
master
git remote add origin
,然后输入git remote -v< /code>
git push -f origin master
main
2.master
main
git checkout main
git merge master
git pull origin main
git push -f origin main
注意:从 2020 年 10 月 1 日起, GitHub 决定使用 main 而不是 master 分支作为默认分支名称。
After the GitHub update 2000-10-01, you should use main instead of master.
Do it like this way...
.git
file in your local directorygit init
git add .
git commit -m"My first commit"
master
in your local projectgit remote add origin <remote repository URL past here from the GitHub repository>
, and then typegit remote -v
git push -f origin master
main
2.master
main
git checkout main
git merge master
git pull origin main
git push -f origin main
Note: from 2020-10-01, GitHub decided use main instead of master branch to use as the default branch name.
只需添加初始提交即可。请按照以下步骤操作:
git add .
git commit -m "initial commit"
< /p>git Push origin master
这适用于我。
Just add an initial commit. Follow these steps:
git add .
git commit -m "initial commit"
git push origin master
This worked for me.
我也遇到了同样的问题,这解决了我的问题:
只需创建一个分支:
git checkout -b“master”
之后,
git push -u origin master
繁荣。
I have faced the same issue, and this solved my problem:
Just make a branch:
git checkout -b "master"
After that,
git push -u origin master
Boom.
2022 年 2 月更新:
如果您的分支是“main”:
运行此命令:
如果您的分支是“master”:
运行此命令:
Feb, 2022 Update:
If your branch is "main":
Run this command:
If your branch is "master":
Run this command:
我的问题是“主”分支尚未在本地创建。
A Quick
创建了主分支,此时,A Quick
将工作推送到了 Git 存储库。
My issue was that the 'master' branch hadn't been created locally yet.
A quick
created the master branch, at which point, a quick
pushed the work up to the Git repository.
也许分支是main而不是master。
尝试
git push origin HEAD:main
或
git push origin main
Maybe the branch is main instead of master.
Try
git push origin HEAD:main
or
git push origin main
GitHub 将默认分支名称从
master
更改为main
。因此,如果您最近创建了存储库,请尝试推送
main
分支:参考
重命名master 的默认分支 (GitHub)
GitHub changed the default branch name from
master
tomain
.So if you created the repository recently, try pushing the
main
branch:Reference
Renaming the default branch from master (GitHub)
当您添加文件但忘记提交和推送时,就会发生这种情况。
因此提交文件然后推送。
This happens when you have added your file, forgot to commit and pushing.
So commit the files and then push.
git add .
git commit -m "message"
git push originbranch
请检查拼写错误,因为这也可能会导致错误。给出那个错误。
git add .
git commit -m "message"
git push origin branch
Please check for spelling mistakes because that could also give that error.
如果您在分离 HEAD 模式下工作时遇到此错误,您可以执行以下操作:
另请参阅:从分离的 head 进行 Git 推送
如果您位于与远程分支不同的本地分支,您可以执行以下操作:
If you get this error while working in detached HEAD mode, you can do this:
See also: Making a Git push from a detached head
If you are on a different local branch than the remote branch, you can do this:
如果您在第一次推动之前忘记承诺,就会发生这种情况。只需运行:
It happens if you forget to commit before pushing for the first time. Just run:
要检查当前状态,
git status
。并按照以下步骤操作:
To check the current status,
git status
.And follow these steps as well:
这只是意味着您忘记进行初始提交,请尝试
This just mean you forgot to do the initial commit, try
当我错过运行时,我遇到了同样的问题:(
你必须至少有一个文件,否则你会再次收到错误。)
I had the same problem when I missed to run:
(You must have at least one file, or you will get the error again.)