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

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'

当前回答

我想这可能会对某人有所帮助。我今天做出了我的第一次重大承诺。我试了很多指南,但总是出错。

首先:将文件cd到目录中初始化git:gitinit提交文件:gitcommit要在有任何模糊的bash命令时强制提交,请单击I插入提交消息要继续:单击Esc

要发送到GitHub存储库,请首先确保已添加用户名和电子邮件:

git config --global user.name 'Your name'
git config --global user.email 'name@mail.com'

继续:

git remote add origin https://github repo url

要推送到存储库:

git push -u origin 'https://github.repo url'

它将提交加载到存储库中。

完成!!!

其他回答

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

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 show ref,看看你有哪些ref。有裁判/主管/主管吗?

由于最近的“在GitHub中用main替换master”操作,您可能会注意到有一个refs/heads/main。因此,以下命令可能会从gitpushoriginHEAD:master更改为gitpushorigin HEAD:main

您可以尝试git push origin HEAD:master作为一个更独立于本地引用的解决方案。这明确表示您希望将本地ref HEAD推送到远程ref master(请参阅git push-refspec文档)。

如果您有Visual Studio代码:

如果不需要跟踪更改,请删除.git文件夹(如果需要,请删除git stash)初始化gitcommit-m“第一次提交”git远程添加原点https://github.com/YOURusername/YOURrepo.git通过Visual Studio代码UI IDE,从左侧面板或(Ctrl+Shift+G)转到源代码控制准备所有更改或部分更改提交您的更改通过左下角按钮(如数字或云图标)同步您的更改。然后Visual Studio代码要求您输入用户名和密码。

如果您拥有存储库的权限,您可以看到:

> git push -u origin master
Fatal: AggregateException encountered.
To https://github.com/your_account/yourrepo.git
 * [new branch]      master -> master
> git status -z -u
> git symbolic-ref --short HEAD
> git rev-parse master
> git rev-parse --symbolic-full-name master@{u}
> git rev-list --left-right master...refs/remotes/origin/master
> git for-each-ref --format %(refname) %(objectname) --sort -committerdate
> git remote --verbose
> git show :ionic.config.json
> git check-ignore -z --stdin

权限问题?解决方案:分叉

我收到这个错误是因为我没有对存储库的推送权限,所以我不得不分叉它,然后我在分叉的存储库上再次执行了pull、commit和push命令。

我遇到的问题是在尝试重置存储库时。我想删除所有历史记录,什么都不做。然而,您必须至少添加一些要提交的内容,所以我只创建了一个空文本文件gitadd。然后gitcommit-m“重置存储库”。