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
35829 0
git push报错:The current branch master has no upstream branch
|
3月前
|
开发工具 git
Push to origin/master was rejected
这篇文章提供了解决在IDEA中遇到"Push to origin/master was rejected"错误的步骤,包括执行特定的git pull命令并使用`--allow-unrelated-histories`选项来合并不相关的仓库历史。
|
6月前
|
网络安全 开发工具 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的解决
82 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‘
|
5月前
|
开发工具 git
出现“error: failed to push some refs to ‘https://github.com/****.git‘”,如何解决问题
出现“error: failed to push some refs to ‘https://github.com/****.git‘”,如何解决问题
589 1
|
6月前
|
开发工具 git
完美解决git 执行git push origin master指令 报错command not found
完美解决git 执行git push origin master指令 报错command not found
172 0
|
运维 Shell 开发工具
【Git异常】Push master to origin/master was rejected by remote
【Git异常】Push master to origin/master was rejected by remote
218 0
|
Shell BI 开发工具
【问题解决】Git报错:failed to push some refs to xxxxx
Git报错:failed to push some refs to xxxxx
429 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
2800 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"。
212 0