[Git Error] failed to push some refs to “××××.git”

简介: [Git Error] failed to push some refs to “××××.git”

1.问题描述:在将本地仓库内容推送至远程仓库Github时出现以下错误。

To github.com:LeowenHungry/Loewen-TestRepository.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:LeowenHungry/Loewen-TestRepository.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

原因分析:上面提示由于您本地库版本比远程库的版本老,导致不能将本地库文件推送到远程库,在git push之前需要先git pull,将您的本地库版本更新到和远程库一样的最新版本。

解决措施:

1.通过git pull 先将本地库更新到与远程库一致的版本,但要注意本地库后来做的修改可能被覆盖,最好使用git fetch(不会自动合并),查看更新情况再有选择合并,或者先将本地库修改过的文件备份,git pull后再重新修改;

再运行git push即可成功。

2.git提供了一种强制上传的方式:git push -f ,它会忽略版本不一致等问题,强制将本地库上传的远程库,但是一定要谨慎使用,因为-f会用本地库覆盖掉远程库,如果远程库上有重要更新,或者有其他同伴做的修改,也都会被覆盖,所以一定要在确定无严重后果的前提下使用此操作。

注:这里我使用方法1的时候又出现了新的问题,所以直接使用了方法2,大家要慎用,我是刚开始的测试,远程里面没有东西,所以用了。

目录
相关文章
|
2天前
|
开发工具 git
在IDEA中配置Git的Push键
在IDEA中配置Git的Push键
8 0
|
21天前
|
开发工具 git
git push 提交后撤回--图文详解
git push 提交后撤回--图文详解
15 1
|
2月前
|
开发工具 git
记IDEA Git版本回退并push到远程操作
记IDEA Git版本回退并push到远程操作
30 1
记IDEA Git版本回退并push到远程操作
|
2月前
|
开发工具 git
|
2月前
|
开发工具 git
Git -- 代码上传错误 error: failed to push some refs to ‘git@gitee.com:JMFive/uni-shop2.git‘
Git -- 代码上传错误 error: failed to push some refs to ‘git@gitee.com:JMFive/uni-shop2.git‘
|
11天前
|
开发工具 git
完美解决git 执行git push origin master指令 报错command not found
完美解决git 执行git push origin master指令 报错command not found
21 0
|
开发工具 git
git push报错:The current branch master has no upstream branch
git push报错:The current branch master has no upstream branch
30079 0
git push报错:The current branch master has no upstream branch
|
项目管理 开发工具 git
git push 报错 pre-receive hook declined
git push 报错 pre-receive hook declined
3115 0
git push 报错 pre-receive hook declined
|
10月前
|
存储 开发工具 git
使用 git push 上传超过100MB文件报错 remote: error: this exceeds GitHub‘s file size limit of 100.00 MB
Git 大文件存储(LFS)用 Git 中的文本指针替换音频示例、视频、数据集和图形等大文件,同时将文件内容存储在 GitHub.com 或 GitHub Enterprise 等远程服务器上。
183 0
|
6月前
|
开发工具 git
git push origin master提交报错解决办法
git push origin master提交报错解决办法
77 0

相关实验场景

更多