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 push报错:The current branch master has no upstream branch
git push报错:The current branch master has no upstream branch
32042 0
git push报错:The current branch master has no upstream branch
|
20天前
|
开发工具 git
出现“error: failed to push some refs to ‘https://github.com/****.git‘”,如何解决问题
出现“error: failed to push some refs to ‘https://github.com/****.git‘”,如何解决问题
|
2月前
|
网络安全 开发工具 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的解决
36 0
|
开发工具 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‘
|
2月前
|
开发工具 git
完美解决git 执行git push origin master指令 报错command not found
完美解决git 执行git push origin master指令 报错command not found
43 0
|
8月前
|
开发工具 git
git push origin master提交报错解决办法
git push origin master提交报错解决办法
95 0
|
9月前
|
运维 Shell 开发工具
【Git异常】Push master to origin/master was rejected by remote
【Git异常】Push master to origin/master was rejected by remote
131 0
|
9月前
|
Shell BI 开发工具
【问题解决】Git报错:failed to push some refs to xxxxx
Git报错:failed to push some refs to xxxxx
182 0
|
开发工具 git
使用git提交到远程仓库报错:Updates were rejected because the remote contains work that you do
使用git提交到远程仓库报错:Updates were rejected because the remote contains work that you do
2298 0
使用git提交到远程仓库报错:Updates were rejected because the remote contains work that you do
|
Shell 开发工具 git
Idea 提交 Push rejected: Push to origin/master was rejected
idea中,发布项目到码云上,当时按照这样的流程添加Git,然后push,提示:push to origin/master war rejected"。
80 0