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

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'

当前回答

两种可能性:

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

其他回答

万一您在执行gitinit并推送初始提交后仍面临此问题。然后,您可以尝试以下操作:,

git checkout -b "new branch name"
git push origin "new branch name"

您的代码将作为新分支推送。

对我来说,我必须确保公钥在服务器(附加在~/.ssh/authorized_keys中)和GitHub/Bitbucket(添加到GitHub或Bitbucket上的ssh密钥中)中正确配置-它们需要匹配。然后:

git add --all :/
git commit -am 'message'
git push -u origin master

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

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

面临的问题

当我在GitHub上创建一个新的存储库并将其与我的客户端计算机上的react应用程序链接时,我也遇到了同样的问题。

我使用了以下步骤:

出现问题之前使用的命令

git init
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main

我的错误

但正如你所见,我的错误是没有使用gitadd。命令我犯了这个错误,因为我已经有了README.md文件,而GitHub在创建存储库时会指导我们使用基本命令。

我的解决方案

我的解决方案是使用gitadd。gitinit命令之后。

按照相同的顺序使用以下命令集来解决问题:

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main

两种可能性:

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