【Git异常】Push master to origin/master was rejected by remote

简介: 【Git异常】Push master to origin/master was rejected by remote

一、背景描述

最近公司的版本管理工具,统一由 SVN 改为 GIT ,今天新分配的 GIT 账号和新项目,拉下来代码发现 push 不上去,以为是自己本地仓库 GIT 账号和新分配的冲突原因呢,我最后统一改成一样的还是 push 失败。

注意:以下是我从 GITmaster 仓库拉取的,然后又从本地提交代码至 master 仓库。然后才出现的这个问题。

remote: GitLab: You are not allowed to push code to protected branches on this project.

Push master to origin/master was rejected by remote

然后在网上搜索有的说是 按照以下命令(打开你要上传代码的文件夹位置鼠标右键git Bash Here然后直接下面两行命令解决问题)就可以了。然而,我试了试,还是不行哦。

git pull origin master --allow-unrelated-histories
git push -u origin master -f

不过这个命令一定要慎用,git push -u origin master -f 是强制推送的意思。强制推送 要慎用!慎用!慎用!重要的事情说三遍!这会让别人提交的代码被覆盖!!!

可以看到,我使用以上命令,依然解决不了问题。

二、原因分析

最后经过与运维同事探讨,原来是他在主分支上添加了限制权限,不允许直接提交到主分支导致的。原因是因为权限不够,master 分支被保护了,所以才会导致这个问题的出现。

三、解决方案

GIT 仓库中,重新创建一个分支:

然后 从这个新创建的分支上 pull 代码,编辑过后,然后 push 到这个 新创建的分支上即可。

完结!


相关文章
|
30天前
|
开发工具 git
记IDEA Git版本回退并push到远程操作
记IDEA Git版本回退并push到远程操作
30 1
记IDEA Git版本回退并push到远程操作
|
1月前
|
开发工具 git
|
1月前
|
开发工具 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‘
|
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的解决
20 0
|
8天前
|
开发工具 git
完美解决git 执行git push origin master指令 报错command not found
完美解决git 执行git push origin master指令 报错command not found
17 0
|
2月前
|
开发工具 git
Git:error: remote origin already exists
Git:error: remote origin already exists
22 2
|
3月前
|
存储 网络安全 数据处理
git远程操作,推送【push】,拉取【pull】,忽略特殊文件,配置别名,标签管理
git远程操作,推送【push】,拉取【pull】,忽略特殊文件,配置别名,标签管理
|
15天前
|
缓存 数据可视化 网络安全
Git命令大全
Git命令大全
46 1
|
19天前
|
开发工具 git
Git教程:深入了解删除分支的命令
【4月更文挑战第3天】
38 0
Git教程:深入了解删除分支的命令
|
1月前
|
存储 Shell Linux
【Shell 命令集合 文件管理】Linux git命令使用教程
【Shell 命令集合 文件管理】Linux git命令使用教程
34 0