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

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'

当前回答

我确实遇到了同样的问题,但在我的情况下,创建新存储库时,从一开始就按照页面上给出的步骤进行操作。

只是在这里粘贴:

  echo "# YYYY" >> README.md
  git init
  git add README.md
  git commit -m "first commit"
  git remote add origin https://github.com/XXXX/YYYY.git
  git push -u origin master

在GitBash中键入上述内容。XXXX是用户名,YYYY是存储库名称。

其他回答

git分支使用-mv标志重命名分支:git分支-mv源主机

在这个git分支之后应该显示master

我也犯了同样的错误;我的问题就是这样解决的:

git config --global user.email "YOUR EMAIL"
git config --global user.name "YOUR NAME"

2021,GitHub将默认分支名称更改为main。以前它是主人。

我之所以痛苦,是因为我试图向不存在的主服务器推送,而远程的分支是主服务器。确保您使用的分支名称正确。

下面的命令对我有效

git push origin main

我走错了路。检查您的分支。我在“主”分支而不是“主”。

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

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

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

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

截至2022年。