我使用以下内容克隆存储库:

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'

当前回答

这对我有用,将存储库重置为远程主存储库:

git checkout master
git commit -a -m "your comment"
git push origin master

其他回答

git push-u原始主机

error: src refspec master does not match any.
error: failed to push some refs to 'http://REPO.git'

这是由于存储库仍然是空的。存储库中没有提交,因此没有主分支可以推送到服务器。

这对我有用

决议

1) git init
2)git commit -m "first commit"
3)git add app
4)git commit -m "first commit"
5)git push -u origin master

在我Git只添加了一个目录之后,我发现这发生在一个全新的存储库中。

一旦我添加了一个文件(例如README),Git推送就非常成功。

如果要在原点远程创建新分支,则需要首先在本地创建相同的分支:

$ git clone -b new-branch
$ git push origin new-branch

关于Aryo的回答:在我的情况下,我必须使用本地Git存储库的完整URL来推送文件。首先,我删除了当前目录中的所有文件,并创建了README。

添加了更多内容。然后我提交了这些文件,最后推送了它们,给了存储库一个正确的URL。这里,您的存储库是服务器上存储库的名称。

rm -rf *

touch README
git add README
touch file1 file2
git add file1 file2

git commit -m "reinitialized files"
git push git@localhost:yourrepository.git master --force

我也遵循了GitHub的指示,如下所示,但我仍然面临着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磁盘)。在复制粘贴上面建议的代码行时,我并没有等到处理器真正完成添加。过程因此,当我键入gitcommit-m“message”时,它基本上没有引用任何文件,也没有完成将代码成功提交到GitHub所需的任何操作。

证明这一点的是,当我键入gitstatus时,通常会为添加的文件使用绿色字体。但所有的东西都是红色的,好像根本没有添加。

所以我重新调整了步骤。我键入了gitadd。并等待文件完成添加。然后我完成了接下来的步骤。