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

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 config --global user.email "YOUR EMAIL"
git config --global user.name "YOUR NAME"

其他回答

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

git pull origin master

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

git push -u origin master

尝试git show ref

你可能会看到refs/heads/live

这意味着你应该这样做

git push -u origin live

两种可能性:

1-要么忘记包含.gitignore文件。

以下是所需的所有步骤:

在远程上创建一个空的Git存储库,在本地创建.gitignore文件。GitHub在这里列出了一些示例启动终端,然后在项目中执行以下命令:git remote添加原点YOUR/origin.gitgit添加。gitcommit-m“初始提交或首次提交的任何消息”git push-u原始主机

2-或者您正在尝试创建一个新的Github项目。

Github将master替换为main作为默认分支名称。要解决此问题,请执行以下操作:

在本地项目上:删除.git文件夹(如果存在)通过在项目中启动以下操作,重新创建一个干净的存储库:

在终端中:

git init

git add .

git commit -m "YOUR FIRST MESSAGE HERE"

git branch -M main

git remote add origin _GIT_LINK_TO_PROJECT_HERE_

git push -u origin main

关于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 push-u origin master,但我得到了错误。

一旦我cd到当前目录,执行gitpush-uorigin-master,一切都很好。