Git推送报错src refspec main不匹配,如何推送到main分支?
问题描述
执行Git提交代码时遇到以下错误:
首次操作流程
D:\Work\htdocs\temp>git add * warning: LF will be replaced by CRLF in .htaccess. The file will have its original line endings in your working directory\ D:\Work\htdocs\temp>git commit -m "first commit" [master 2f28669] first commit 1 file changed, 6 insertions(+) create mode 100644 .htaccess D:\Work\VikasSite\htdocs\temp>git push fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin master
后续修正操作(仍失败)
D:\Work\htdocs\temp>git push origin --delete master To https://github.com/*******/php_social_network.git - [deleted] master D:\Work\htdocs\temp>git commit -m "test" [master *****] test 2 files changed, 39 insertions(+) create mode 100644 github create mode 100644 github.pub D:\Work\htdocs\temp>git push --set-upstream origin main error: src refspec main does not match any error: failed to push some refs to 'https://github.com/******/php_social_network.git'
错误原因
你本地当前的分支还是master,但尝试推送到远程的main分支——本地根本不存在main分支,所以Git找不到对应的分支进行推送,抛出src refspec main does not match any错误。
解决步骤
- 将本地
master分支重命名为maingit branch -m master main - 设置上游分支并推送代码
这条命令会把本地的git push --set-upstream origin mainmain分支推送到远程仓库,同时将远程main设置为本地分支的上游,之后直接用git push就能同步代码。
如果远程仓库还没有main分支,上述推送命令会自动在远程创建该分支;如果已经存在,则直接同步本地提交。
内容的提问来源于stack exchange,提问作者Mich
相关产品推荐
相关产品推荐

