我克隆了我的存储库:
git clone ssh://xxxxx/xx.git
Run Code Online (Sandbox Code Playgroud)
但之后,我改变了一些文件,并add与commit他们,我想他们推到服务器:
git add xxx.php
git commit -m "TEST"
git push origin master
Run Code Online (Sandbox Code Playgroud)
但我得到的错误是:
error: src refspec master does not match any.
error: failed to push some refs to 'ssh://xxxxx.com/project.git'
Run Code Online (Sandbox Code Playgroud)
小智 3799
也许你只需要提交.我做的时候碰到了这个:
mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .
Run Code Online (Sandbox Code Playgroud)
哎呀!永不承诺!
git push -u origin master
error: src refspec master does not match any.
Run Code Online (Sandbox Code Playgroud)
我所要做的就是:
git commit -m "initial commit"
git push origin master
Run Code Online (Sandbox Code Playgroud)
成功!
Vi.*_*Vi. 775
试着git show-ref看看你有什么裁判.有refs/heads/master吗?
您可以尝试git push origin HEAD:master更多与本地参考无关的解决方案.这明确指出您要将本地引用推HEAD送到远程引用master(请参阅git-push refspec文档).
Ary*_*ryo 217
删除本地计算机中的所有文件后,我也遇到了类似的错误,我必须清理存储库中的所有文件.
我的错误信息是这样的:
error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'
Run Code Online (Sandbox Code Playgroud)
并通过执行以下命令解决:
touch README
git add README
git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force # <- caution, --force can delete others work.
Run Code Online (Sandbox Code Playgroud)
就是这样,希望这会有所帮助.
tld*_*ldr 185
所以我尝试了Vi的解决方案:
git push origin HEAD:<remoteBranch>
Run Code Online (Sandbox Code Playgroud)
这对我有用.
VIK*_*HLI 118
git push -u origin master
error: src refspec master does not match any.
Run Code Online (Sandbox Code Playgroud)
为此,您需要输入如下的提交消息,然后按下代码
git commit -m "initial commit"
git push origin master
Run Code Online (Sandbox Code Playgroud)
成功地推向了主人
Red*_*Red 107
对我来说,我必须确保公钥在服务器中正确配置(附加在〜/ .ssh/authorized_keys中)和github/bitbucket(添加到我在github或bitbucket上的SSH密钥) - 它们需要匹配.
然后:
git add --all :/
git commit -am 'message'
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
最后为我工作.
And*_*w E 78
在git只添加了一个目录后,我发现这发生在一个全新的存储库中.
一旦我添加了一个文件(例如README),git push就能很好地工作.
aug*_*uag 67
丢失或跳过git add .或git commit可能导致此错误:
git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://yourusername@github.com':
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'
Run Code Online (Sandbox Code Playgroud)
要修复它,请重新初始化并遵循正确的顺序:
git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
小智 60
要修复它,请重新初始化并遵循正确的代码序列:
git init
git add .
git commit -m 'message'
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
Sau*_*ngh 54
确保先添加,然后提交/推送:
喜欢:
git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
wil*_*foz 43
当您在特定分支中并尝试推送另一个尚不存在的分支时,也会发生这种情况,例如:
$ git branch
* version-x # you are in this branch
version-y
$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin_address'
Run Code Online (Sandbox Code Playgroud)
小智 41
对我来说,以下工作可以移动未跟踪的文件:
git add --all
Run Code Online (Sandbox Code Playgroud)
接下来,我遵循了类似的步骤
git commit -m "First commit"
Run Code Online (Sandbox Code Playgroud)
然后,
git remote add origin git@github.....
Run Code Online (Sandbox Code Playgroud)
最后但是同样重要的:
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
执行此操作时,Windows 安全将弹出要求您输入用户名和密码。
Ars*_*mad 41
几天前我遇到了同样的问题。
如果您现在(2020 年)创建了一个新存储库,那么默认分支是GitHub 上的main。
您现在可以在您的存储库分支中检查 GitHub。
您还可以通过运行以下命令在终端上检查分支:
git branch
Run Code Online (Sandbox Code Playgroud)
所以这就是为什么你需要运行
git push origin main
Run Code Online (Sandbox Code Playgroud)
代替
git push origin master
Run Code Online (Sandbox Code Playgroud)
祝你好运
Md.*_*ana 28
在 GitHub 更新 01.10.20 之后,您应该使用 main 而不是 master。
像这样做...
Create a repository on GitHub.git本地目录中的现有文件git initgit add .git commit -m"My First Commmit"master在您的本地项目中git remote add origin <remote repository URL past here from the github repository> 然后输入 git remote -vgit push -f origin mastermain2.mastermaingit checkout maingit merge mastergit pull origin maingit push -f origin main注意:从 01.10.20 github 决定使用main而不是master分支使用默认分支名称
小智 28
如果您的分支是“main”:
运行这个命令:
git push origin main
Run Code Online (Sandbox Code Playgroud)
如果您的分支是“master”:
运行这个命令:
git push origin master
Run Code Online (Sandbox Code Playgroud)
Nee*_*ngh 26
只需添加初始提交,请按照以下步骤操作: -
git add.
git commit -m"initial commit"
git push origin master
这对我有用
Ism*_*l H 23
就我而言,我忘记了包含.gitignore文件。这是所需的所有步骤:
启动终端,然后在您的项目中执行以下命令:
git remote add origin YOUR/ORIGIN.git
git add .
git commit -m "initial commit or whatever message for first commit"
git push -u origin master
Run Code Online (Sandbox Code Playgroud)Asw*_*ath 23
当我在 GitHub 上创建一个新存储库并将其与我拥有的客户端计算机中的 react-app 链接时,我遇到了同样的问题。
我使用了以下步骤:
git init
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main
Run Code Online (Sandbox Code Playgroud)
但是正如你所看到的,我的错误是没有使用git add .命令,我犯了这个错误,因为我已经有了 README.md 文件,GitHub 在创建存储库时用基本命令指导我们。
我的解决方案是git add .在git init命令之后使用。
以相同的顺序使用以下一组命令来解决这个问题:
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main
Run Code Online (Sandbox Code Playgroud)
Ant*_*ony 19
我的问题是"主"分支尚未在本地创建.
快点
git checkout -b "master"
Run Code Online (Sandbox Code Playgroud)
创建了主分支,在这一点上,快速:
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
推动工作到git repo.
Jin*_*won 19
我遇到了同样的问题而且我用过--allow-empty.
$ git commit -m "initial commit" --allow-empty
...
$ git push
...
Run Code Online (Sandbox Code Playgroud)
小智 18
这只是意味着你忘了做初始提交,试试
git add .
git commit -m 'initial commit'
git push origin master
Run Code Online (Sandbox Code Playgroud)
neo*_*Dev 18
我错过了跑步时遇到了同样的问题:
git add .
Run Code Online (Sandbox Code Playgroud)
(您必须至少有一个文件,否则您将再次收到错误)
Gel*_*Gel 18
我还遵循了以下GitHub的指示,但是我仍然遇到OP提到的相同错误:
git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
对我来说,希望对我有帮助,我(1.58 GB on disk)在MacOS上推送了一个大文件。复制粘贴上面建议的代码行时,我没有等待处理器真正完成该add .过程。因此,当我键入内容时,git commit -m "message"它基本上没有引用任何文件,也没有完成将代码成功提交到GitHub所需的任何操作。
证明是,当我git status通常键入内容时,添加的文件会显示绿色字体。但是,一切都是红色的。好像根本没有添加。
因此,我重新执行了步骤。我键入git add .并等待文件添加完成。然后,我按照以下步骤进行操作。
Dee*_*and 17
简短回答:此错误意味着您要远程推送的分支不存在!
就我而言,从 2020 年 10 月开始,此后创建的存储库拥有main分支而不是前一个master分支。所以我不得不这样做:
git push -u origin main
Run Code Online (Sandbox Code Playgroud)
答对了!那对我有用!希望有帮助!快乐编码!
Aad*_*Ura 17
我遇到了同样的问题并在这里尝试了大部分答案,但问题是由于 Github 重命名最近的变化。
GitHub 正在逐步将存储库的默认分支从 重命名master为main。
https://github.com/github/renaming
你的新命令是:
git push origin main
Run Code Online (Sandbox Code Playgroud)
而不是这个:
git push origin master
Run Code Online (Sandbox Code Playgroud)
Bad*_*laj 16
如果您在第一次推送之前忘记提交,就会发生这种情况。赶紧跑:
git commit -m "first commit"
Run Code Online (Sandbox Code Playgroud)
Din*_*ith 15
要检查当前状态,git status。
并遵循以下步骤:
git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
Ala*_*min 15
我遇到了同样的问题,
解决了我的问题。
只需创建一个分支:
git checkout -b "master"
在那之后
git push -u origin master
砰。
希望它会得到解决。
AAY*_*ANE 14
在 2021 年,github 将默认分支名称更改为main以前的名称master,因为我试图推送到master不存在的分支,而远程分支是,因此我遭受了痛苦main,请确保您使用正确的分支名称。
下面的命令对我有用
git push origin main
Run Code Online (Sandbox Code Playgroud)
use*_*460 13
我有同样的问题.我是通过以下步骤来做到的
1. git commit -m 'message'
2. git config --global user.email "your mail"
3. git config --global user.name "name"
4. git commit -m 'message'
5. git push -u origin master
Run Code Online (Sandbox Code Playgroud)
希望它会帮助任何人
d.r*_*aev 13
在您从外部源检出仓库并想要在个人/内部系统中导入它的场景中,此命令真正闪耀:
git push --all origin
Run Code Online (Sandbox Code Playgroud)
这会推动所有分支,而不检查引用,坚持提交.
sna*_*nap 13
如果在分离HEAD模式下工作时出现此错误,则可以执行以下操作:
git push origin HEAD:remote-branch-name
Run Code Online (Sandbox Code Playgroud)
另请参阅: 从分离的头部进行git推送
如果您位于与远程分支不同的本地分支上,则可以执行以下操作:
git push origin local-branch-name:remote-branch-name
Run Code Online (Sandbox Code Playgroud)
Gov*_*ind 10
如果您在执行git init并推送初始提交后仍遇到此问题.您可以尝试以下方式,
git checkout -b "new branch name"
git push origin "new branch name"
Run Code Online (Sandbox Code Playgroud)
您的代码将作为新分支推送.
Gya*_*thi 10
git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'http://REPO.git'
Run Code Online (Sandbox Code Playgroud)
这是由于存储库仍然是空的。存储库中没有提交,因此没有要推送到服务器的主分支。
它对我有用
解析度
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
Run Code Online (Sandbox Code Playgroud)
Sid*_*qui 10
2020 年底,GitHub 将master分支改为main分支
我注意到 GitHub 创建了一个新的 master 分支,这不是我使用时的主分支git push -u origin master:
现在,当我尝试使用git push -u origin main, 直接推送到主分支时,它给了我这个错误:
我遇到了这个错误:
src refspec main does not match any
error: failed to push some refs to 'https://github.com/<my_project_name>.git
Run Code Online (Sandbox Code Playgroud)
在我第一次提交main.Change URL后,我在以下代码中修复了 GitHub 的使用这些步骤:
git branch -M main
git remote add origin https://github.com/Sidrah-Madiha/<my_project_url>.git
git push -u origin main
Run Code Online (Sandbox Code Playgroud)
Shi*_*nto 10
可能您当前的分支没有上游分支。当您第一次推送时尝试这些命令。
git init
git add .
git status
git commit -m "initial commit"
git remote add origin "github.com/your_repo.git"
git push --set-upstream origin master
Run Code Online (Sandbox Code Playgroud)
小智 9
You need to config your git if is the first time that you use it with:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Run Code Online (Sandbox Code Playgroud)
当您尝试将空仓库推送到 git 服务器时会发生此错误。这可以通过初始化README.md文件来缓解:
cat > README.md
Run Code Online (Sandbox Code Playgroud)
然后输入一些东西,然后回车,然后CTRL+D保存。然后是通常的提交步骤:
git add .
git commit -m "Initial commit"
git push origin master
Run Code Online (Sandbox Code Playgroud)
小智 9
Github 将默认分支名称从 更改master为main. 因此,如果您最近创建了 repo,请尝试 pushmain分支
git push origin main
Run Code Online (Sandbox Code Playgroud)
我忘了在提交之后和推送之前做一个"git pull origin master",它会导致同样的问题:"当在git中提交提交时,src refspec master不匹配".那么,你应该做的是:
1. git add .
2. git pull origin master
3. git commit -am "Init commit"
4. git push origin master
Run Code Online (Sandbox Code Playgroud)
为避免在 2021 年及以后陷入此错误,请在使用前使用此命令 git init
git config --global init.defaultBranch main
这告诉您的 gitmain始终用作默认分支名称,而不是master
小智 8
我也面临同样的问题。就我而言,我在添加之前错误地进行了提交。按顺序执行这些步骤后,我明白了。
另请确保提供正确的分支机构名称。
git init
git add .
git commit -m <Your commit message>
git remote add origin "your repository link here"
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
小智 8
当我第一次推送到存储库时,我遇到了同样的问题。我忘记提交任何更改并尝试做
git push -u origin main
Run Code Online (Sandbox Code Playgroud)
通过添加提交然后执行来解决此问题:
git push -u origin main
Run Code Online (Sandbox Code Playgroud)
试试这个:
git add .
git commit -m "your commit message"
git remote add origin *remote repository URL*
git push origin *your-branch-name*
Run Code Online (Sandbox Code Playgroud)
小智 7
就我而言,我克隆了一个存储库,但我没有切换到本地的分支。
我通过这样做解决了它:
在更改代码之前,您应该这样做:
git checkout branch-name
Run Code Online (Sandbox Code Playgroud)
然后修改你的代码
之后将代码推送到分支:
git push -u origin branch-name
Run Code Online (Sandbox Code Playgroud)
另外,如果您是第一次将本地存储库推送到 GitHub,则需要先创建一个main分支:
git branch -M main
Run Code Online (Sandbox Code Playgroud)
然后,在添加origin(或您给远程的任何名称)后推送分支:
git push -u origin main
Run Code Online (Sandbox Code Playgroud)
小智 6
这对我来说重置为远程主控回购
git checkout master
git commit -a -m "your comment"
git push origin master
Run Code Online (Sandbox Code Playgroud)
此问题的另一个可能原因是您拼错了分支名称.所以,如果你做了我做的事情,那么问题将通过纠正:
git push origin mater
Run Code Online (Sandbox Code Playgroud)
至
git push origin master
Run Code Online (Sandbox Code Playgroud)
添加空目录时出现此问题.Git不允许推送空目录.这是一个简单的解决方案.
在要推送到远程的目录中创建文件.gitkeep,并从命令行提交"空"目录:
touch your-directory/.gitkeep
git add your-directory/.gitkeep
git commit -m "Add empty directory"
Run Code Online (Sandbox Code Playgroud)
检查你的提交标题,因为如果你忘记了git commit -m"xxxx"命令,你会遇到同样的问题
git commit -m "initial commit"
Run Code Online (Sandbox Code Playgroud)
面对同样的问题,但在我的情况下,在创建新的Repository工作时,按照页面上给出的确切步骤进行操作.只是粘贴在这里
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
Run Code Online (Sandbox Code Playgroud)
在GitBash XXXX中输入上面的用户名,YYYY输入存储库名称.
小智 6
对我有用的只是结帐到我希望我的代码推送的分支,然后简单地推送您的代码。
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
Run Code Online (Sandbox Code Playgroud)
我有类似的错误。但 Git 告诉我:
*** Please tell me who you are.
Run Code Online (Sandbox Code Playgroud)
跑步
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Run Code Online (Sandbox Code Playgroud)
或者设置您帐户的默认身份。
Omit --global to set the identity only in this repository.
Run Code Online (Sandbox Code Playgroud)
然后错误就消失了。
当我没有引用 origin 的 master 分支时,这发生在我身上。因此,您可以尝试以下操作:
git pull origin master
Run Code Online (Sandbox Code Playgroud)
这将创建对本地存储库中源的 master 分支的引用。然后就可以将本地仓库推送到源站了。
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
也许 GitHub 不知道你是谁。
首先你必须运行:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Run Code Online (Sandbox Code Playgroud)
尝试 git show-ref
你可能会看到 refs/heads/live
这意味着你应该做
git push -u origin live
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题......解决方案是将代码推送到 repo,就好像它是一个现有项目而不是一个正在初始化的全新项目。
git remote add origin https://github.com/Name/reponame.git
git branch -M main
git push -u origin main
Run Code Online (Sandbox Code Playgroud)
首先确保您使用的是 master 分支。在我的情况下,分支是主而不是主。所以我所做的是
git push origin main
Run Code Online (Sandbox Code Playgroud)
你可以在这张照片中看到结果
我今天也遇到了同样的问题。我创建了一个新的 repo 并将其克隆到我的机器上。我提交了我的代码并试图推动它。我得到了同样的错误。我观察到这是因为我正在使用:
git push origin master
我在这里做错的是我假设我的默认分支是masterGitHub 上的新默认分支是main. 我推使用:
git push origin main
它工作正常。
我的解决方案仅适用于较新的存储库或最近面临此问题的人,因为 GitHub 正在替换main过度master术语。因此,如果您收到此错误,请务必检查您要推送到的分支以及 GitHub 上的分支名称。
对于Repositories WIKI,我也遇到了这个错误。
git show-branch
Run Code Online (Sandbox Code Playgroud)
如果显示 master 那么
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1725520 次 |
| 最近记录: |