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

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 push -u origin master

随后的命令对我有效

从以下命令开始

git init
git add .
git commit -m "second commit"

所以在推送它之前,运行这些命令,看看我们的本地存储库连接到Github上的哪个远程存储库,以及您所在的分支。

git remote
git branch

远程-->原点

分支-->主

git push -u remote branch

或更具体地:

git push -u origin main

其他回答

GitHub更新01.10.20后,您应该使用main而不是master。

这样做。。。

在GitHub上创建存储库删除本地目录中现有的.git文件转到本地项目目录并键入gitinitgit添加。gitcommit-m“我的第一次通信”现在检查您的分支机构名称,它将在您的本地项目中处于主导地位gitremoteadd origin<github存储库中的远程存储库URL>,然后键入gitremote-vgit push-f原始主机现在检查github存储库,您将看到两个分支1。主要2。主人在本地存储库中创建新分支,分支名称将为maingit结帐总管git合并主机git拉起点总管git push-f origin main

注意:从2010年10月1日起,github决定使用main而不是master分支使用默认分支名称

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

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

当我没有提到起源的主分支时,这发生在我身上。因此,您可以尝试以下操作:

git pull origin master

这将在本地存储库中创建对源的主分支的引用。然后,您可以将本地存储库推送到源位置。

git push -u origin master

关于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

我有一个非常长的本地分行名称。

git branch -m new_shorter_branch_name

解决了问题。