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

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 add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

其他回答

对我来说,只需签出我希望代码推送的分支,然后简单地推送您的代码。

git checkout -b branchname-on-which-i-will-push-my-code

git add .
git commit -m "my commit message"
git push origin branchname-on-which-i-will-push-my-code

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

我在错误的目录中创建了文件,尝试执行git push-u origin master,但我得到了错误。

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

由于多种原因,您可能会遇到此问题。

1.暂存文件的待定提交

如果您通过运行gitadd命令(即gitadd.)添加了更改,并且从未提交过这些文件,则在之后,尝试将分支推入远程存储库。在这种情况下,您将面临src-refspec-master不匹配的错误。

2.本地分支机构名称无效

如果您在分支的名称中键入了错误(即mster而不是master),则会导致此错误。表示您尝试推入的分支不在本地存储库中。

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分支使用默认分支名称