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

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 init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master

其他回答

git push-u原始主机

error: src refspec master does not match any.
error: failed to push some refs to 'http://REPO.git'

这是由于存储库仍然是空的。存储库中没有提交,因此没有主分支可以推送到服务器。

这对我有用

决议

1) git init
2)git commit -m "first commit"
3)git add app
4)git commit -m "first commit"
5)git push -u origin master

我曾经遇到过这个问题,因为我在远程回购上有一个分支,但不是本地的。我做到了:gitfetch&&gitcheckout‘在这里添加远程分支名称’,这解决了我的问题。有时,当您不准备更改时会出现问题,因此,要做到这一点,您需要运行以下git命令:git-add your_file_name.extension或git-add。添加所有更改。此时,您需要通过以下方式提交更改:gitcommit-m'您的提交消息在这里'。完成所有这些操作后,只需通过以下方式将更改推送到远程回购:git推送原点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

首先,您需要gitinit来创建您自己的.git文件,否则如果您克隆了某个git文件夹,它将无法识别您的git凭据。启动git后,继续执行gitadd。和gitcommit。。。

2020年:

如果30个以上的答案都无效,您可能需要运行git push origin main(在编写此答案时,master已重命名为main)。