push to origin/master was rejected错误解决方案

简介: push to origin/master was rejected错误解决方案

idea集成git执行push推送远程仓库,提示:push to origin/master war rejected"。远程仓库拒绝

2021033010450990.png


原因是:初始化项目时,远程仓库建了README.md文件,而本地仓库与远程仓库尚未进行文件关联,因此需要将两个仓库的文件进行关联后提交。


解决方案:


切换到自己项目所在的目录,右键选择GIT BASH Here,Idea中可使用Alt+F12

在terminl窗口中依次输入命令:

git pull
git pull origin master
git pull origin master --allow-unrelated-histories


  1. 在idea中重新push


其他方案


  • 强制 push(保留本地代码,覆盖远程代码)
# 强制push 保留本地代码,覆盖远程代码
git push -u origin master -f
git push -u origin branch_name -f
  • 强制 pull(保留远程代码,覆盖本地代码)
# 强制pull保留远程代码
git fetch --all
# 然后,有两个选择
git reset --hard origin/master
# 其他分支
git reset --hard origin/<branch_name>


相关文章
|
编译器 开发工具 git
【Git异常】You are in ‘detached HEAD‘ state, which means that you‘re not on any branch Checkout a branch
【Git异常】You are in ‘detached HEAD‘ state, which means that you‘re not on any branch Checkout a branch
310 0
|
开发工具 git
git push报错:The current branch master has no upstream branch
git push报错:The current branch master has no upstream branch
36990 0
git push报错:The current branch master has no upstream branch
|
开发工具 git
git报错error: failed to push some refs to ‘https://gitee.com/XXX/XXX-mater.git‘
git报错error: failed to push some refs to ‘https://gitee.com/XXX/XXX-mater.git‘
git报错error: failed to push some refs to ‘https://gitee.com/XXX/XXX-mater.git‘
|
5月前
|
开发工具 git
Push to origin/master was rejected
这篇文章提供了解决在IDEA中遇到"Push to origin/master was rejected"错误的步骤,包括执行特定的git pull命令并使用`--allow-unrelated-histories`选项来合并不相关的仓库历史。
|
8月前
|
网络安全 开发工具 git
git修改提交路径以及强制提交——异常:error: remote origin already exists.与异常:error: failed to push some refs to的解决
git修改提交路径以及强制提交——异常:error: remote origin already exists.与异常:error: failed to push some refs to的解决
109 0
|
7月前
|
开发工具 git
出现“error: failed to push some refs to ‘https://github.com/****.git‘”,如何解决问题
出现“error: failed to push some refs to ‘https://github.com/****.git‘”,如何解决问题
875 1
|
8月前
|
开发工具 git
完美解决git 执行git push origin master指令 报错command not found
完美解决git 执行git push origin master指令 报错command not found
238 0
|
开发工具 git
【Git】push代码时候报错,出现fatal: unable to access xxx Recv failure: Connection was reset
【Git】push代码时候报错,出现fatal: unable to access xxx Recv failure: Connection was reset
266 0
|
运维 Shell 开发工具
【Git异常】Push master to origin/master was rejected by remote
【Git异常】Push master to origin/master was rejected by remote
377 0
|
Shell BI 开发工具
【问题解决】Git报错:failed to push some refs to xxxxx
Git报错:failed to push some refs to xxxxx
637 0