我克隆我的存储库:
git clone ssh://xxxxx/xx.git
但在我更改了一些文件和add
和commit
之后,我想将它们推送到服务器:
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'
也许你只需要提交。我做的时候碰到了这个:
mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .
哎呀!永不承诺!
git push -u origin master
error: src refspec master does not match any.
我所要做的就是:
git commit -m "initial commit"
git push origin master
成功!
确保先添加,然后提交/推送:
喜欢:
git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
当您在特定分支中并尝试推送另一个尚不存在的分支时,也会发生这种情况,例如:
$ git branch
* version-x # you are in this branch
version-y
$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin_address'
只需添加初始提交,请按照以下步骤操作: -
我遇到了同样的问题,我使用了--allow-empty
。
$ git commit -m "initial commit" --allow-empty
...
$ git push
...
这只是意味着你忘了做初始提交,试试
git add .
git commit -m 'initial commit'
git push origin master
我的问题是'master'分支尚未在本地创建。
快点
git checkout -b "master"
创建了主分支,在这一点上,快速:
git push -u origin master
推动工作到git repo。
我错过了跑步时遇到了同样的问题:
git add .
(您必须至少有一个文件,否则您将再次收到错误)
我也按照下面的方式遵循githubs的指示,但仍然遇到OP提到的同样的错误:
git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
对我来说,我希望这有些帮助,我在我的MacOS上推了一个大文件(1.58 GB on disk)
。在复制粘贴上面建议的代码行时,我并没有等待我的处理器实际完成add .
进程。因此,当我输入git commit -m "message"
时,它基本上没有引用任何文件,并且没有完成将成功提交我的代码到github所需要做的任何事情。
证明这一点是当我输入git status
时,通常我会为添加的文件获取绿色字体。但一切都是红色的。好像根本没有添加。
所以我重新制定了步骤。键入git add .
并等待文件完成添加。然后按照下面的步骤操作。
我希望这可以帮助别人。
你可能忘记了命令“git add”。在“git init”命令之后。
git show-ref
看看你有什么裁判。有没有refs/heads/master
?git push origin HEAD:master
作为更多本地参考独立解决方案。这明确指出你想将本地ref HEAD
推送到远程ref master
(参见git-push refspec文档)。添加文件,忘记提交和推送时会发生这种情况。所以提交文件然后推送。
我有同样的问题。我是通过以下步骤来做到的
1. git commit -m 'message'
2. git config --global user.email "your mail"
3. git config --global user.name "name"
4. git commit -m 'message'
5. git push -u origin master
希望它会帮助任何人
git add。
是你需要的所有代码跟踪你的目录中所有未跟踪的文件
如果在分离HEAD模式下工作时出现此错误,则可以执行以下操作:
git push origin HEAD:remote-branch-name
另见:making a git push from a detached head
如果您位于与远程分支不同的本地分支上,则可以执行以下操作:
git push origin local-branch-name:remote-branch-name
如果您尝试推送的分支名称中有拼写错误,也会发生这种情况。
如果您在执行git init并推送初始提交后仍遇到此问题。您可以尝试以下方式,
git checkout -b "new branch name"
git push origin "new branch name"
您的代码将作为新分支推送。
在您从外部存储库(GitHub)签出代码的场景中, 并希望在个人/内部系统中导入它,
这个命令真的很棒:
git push --all origin
这将所有本地分支推送到远程, 没有检查refs,没有坚持提交。
如果您是第一次使用它,则需要配置您的git:
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
我忘了在提交之后和推送之前做一个“git pull origin master”,它会导致同样的问题:“当在git中提交提交时,src refspec master不匹配”。那么,你应该做的是:
1. git add .
2. git pull origin master
3. git commit -am "Init commit"
4. git push origin master
试试这个:
git add .
git commit -m "your commit message"
git remote add origin *remote repository URL*
git push origin *your-branch-name*
删除本地计算机中的所有文件后,我也遇到了类似的错误,我必须清理存储库中的所有文件。
我的错误信息是这样的:
error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'
并通过执行以下命令解决:
touch README
git add README
git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force # <- caution, --force can delete others work.
就是这样,希望这会有所帮助。
这对我来说重置为远程主控回购
git checkout master
git commit -a -m "your comment"
git push origin master
git push -u origin master
error: src refspec master does not match any.
为此,您需要输入如下的提交消息,然后按下代码
git commit -m "initial commit"
git push origin master
成功推向掌握
对我来说,我必须确保公钥在服务器中正确配置(附加在〜/ .ssh / authorized_keys中)和github / bitbucket(添加到我在github或bitbucket上的SSH密钥) - 它们需要匹配。
然后:
git add --all :/
git commit -am 'message'
git push -u origin master
最后为我工作。
在git只添加了一个目录后,我发现这发生在一个全新的存储库中。
一旦我添加了一个文件(例如README),git push就能很好地工作。
丢失或跳过git add .
或git commit
可能会导致此错误:
git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://[email protected]':
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'
要修复它,请重新初始化并遵循正确的顺序:
git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master
要修复它,请重新初始化并遵循正确的代码序列:
git init
git add .
git commit -m 'message'
git push -u origin master