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

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'

当前回答

对我来说,这似乎是因为我已经完成了提交过程,所以我在尝试再次提交后得到了这个结果。

Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

因为我看到路径是origin/main,所以我将其推到main而不是master,并且它起了作用。

注意:检查以确定主分支是主分支还是主分支。

截至2022年。

其他回答

对我来说,以下操作可以移动未跟踪的文件:

git add --all

接下来,我遵循了类似的步骤

 git commit -m "First commit"

然后

git remote add origin git@github.....

最后但并非最不重要的是:

git push -u origin master

当您执行此操作时,Windows安全将弹出窗口,询问您的用户名和密码。

添加空目录时遇到此问题。Git不允许推送空目录。这里有一个简单的解决方案。

在要推送到远程的目录中创建文件.gitkeep,并从命令行提交“空”目录:

touch your-directory/.gitkeep
git add your-directory/.gitkeep
git commit -m "Add empty directory"

试试看:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

在我的例子中,出现在Windows上的问题似乎与我们在分支名称中添加前缀类似feature\有关。我们试图创建并推送一个具有这样前缀的分支(例如,feature\branch),但已经有一个不同的分支,其前缀为feature\(例如,feature\otherbranch)。这意味着在Windows上,新分支被放置在相同的refs\heads\Feature文件夹中。Git可能区分大小写,但Windows文件系统不区分大小写。一旦我们签出了名为Feature\branch的本地分支,它就起到了作用。

来自Git的错误:

错误:src-refspec-master与任何不匹配。

已修复此步骤:

git commit -m "first commit"

在我跑步之前:

git add <files>

在我跑步后:

git push -u origin master