多种方法解决 git 推送push代码出现github远程分支拒绝[remote rejected] (push declined due to repository rule violations

多种方法解决 git 推送push代码出现github远程分支拒绝[remote rejected] (push declined due to repository rule violations。

在这里插入图片描述

出现错误类似如下:

11:07:29.408: [goutils] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin 40e3c6c07ca483573ea5077acb6d6d4426c0ef9a:refs/heads/main
Enumerating objects: 30, done.
Counting objects: 3% (1/30)
Counting objects: 6% (2/30)
Counting objects: 10% (3/30)
Counting objects: 13% (4/30)
Counting objects: 16% (5/30)
Counting objects: 20% (6/30)
Counting objects: 23% (7/30)
Counting objects: 26% (8/30)
Counting objects: 30% (9/30)
Counting objects: 33% (10/30)
Counting objects: 36% (11/30)
Counting objects: 40% (12/30)
Counting objects: 43% (13/30)
Counting objects: 46% (14/30)
Counting objects: 50% (15/30)
Counting objects: 53% (16/30)
Counting objects: 56% (17/30)
Counting objects: 60% (18/30)
Counting objects: 63% (19/30)
Counting objects: 66% (20/30)
Counting objects: 70% (21/30)
Counting objects: 73% (22/30)
Counting objects: 76% (23/30)
Counting objects: 80% (24/30)
Counting objects: 83% (25/30)
Counting objects: 86% (26/30)
Counting objects: 90% (27/30)
Counting objects: 93% (28/30)
Counting objects: 96% (29/30)
Counting objects: 100% (30/30)
Counting objects: 100% (30/30), done.
Delta compression using up to 8 threads
Compressing objects: 5% (1/19)
Compressing objects: 10% (2/19)
Compressing objects: 15% (3/19)
Compressing objects: 21% (4/19)
Compressing objects: 26% (5/19)
Compressing objects: 31% (6/19)
Compressing objects: 36% (7/19)
Compressing objects: 42% (8/19)
Compressing objects: 47% (9/19)
Compressing objects: 52% (10/19)
Compressing objects: 57% (11/19)
Compressing objects: 63% (12/19)
Compressing objects: 68% (13/19)
Compressing objects: 73% (14/19)
Compressing objects: 78% (15/19)
Compressing objects: 84% (16/19)
Compressing objects: 89% (17/19)
Compressing objects: 94% (18/19)
Compressing objects: 100% (19/19)
Compressing objects: 100% (19/19), done.
Writing objects: 5% (1/19)
Writing objects: 10% (2/19)
Writing objects: 15% (3/19)
Writing objects: 21% (4/19)
Writing objects: 26% (5/19)
Writing objects: 31% (6/19)
Writing objects: 36% (7/19)
Writing objects: 42% (8/19)
Writing objects: 47% (9/19)
Writing objects: 52% (10/19)
Writing objects: 57% (11/19)
Writing objects: 63% (12/19)
Writing objects: 68% (13/19)
Writing objects: 73% (14/19)
Writing objects: 78% (15/19)
Writing objects: 84% (16/19)
Writing objects: 89% (17/19)
Writing objects: 94% (18/19)
Writing objects: 100% (19/19)
Writing objects: 100% (19/19), 11.99 KiB | 3.00 MiB/s, done.
Total 19 (delta 9), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 0% (0/9)
remote: Resolving deltas: 11% (1/9)
remote: Resolving deltas: 22% (2/9)
remote: Resolving deltas: 33% (3/9)
remote: Resolving deltas: 44% (4/9)
remote: Resolving deltas: 55% (5/9)
remote: Resolving deltas: 66% (6/9)
remote: Resolving deltas: 77% (7/9)
remote: Resolving deltas: 88% (8/9)
remote: Resolving deltas: 100% (9/9)
remote: Resolving deltas: 100% (9/9), completed with 9 local objects.
remote: error: GH013: Repository rule violations found for refs/heads/main.
remote:
remote: - GITHUB PUSH PROTECTION
remote: —————————————————————————————————————————
remote: Resolve the following violations before pushing again
remote:
remote: - Push cannot contain secrets
remote:
remote:
remote: (?) Learn how to resolve a blocked push
remote: https://docs.github.com/code-security/secret-scanning/pushing-a-branch-blocked-by-push-protection
remote:
remote: (?) This repository does not have Secret Scanning enabled, but is eligible. Enable Secret Scanning to view and manage detected secrets.
remote: Visit the repository settings page, https://github.com/AbnerEarl/goutils/settings/security_analysis
To https://github.com/AbnerEarl/goutils.git
remote:
! 40e3c6c07ca483573ea5077acb6d6d4426c0ef9a:refs/heads/main [remote rejected] (push declined due to repository rule violations)
remote:
Done
remote: —— Alibaba Cloud AccessKey ID ————————————————————————
remote: locations:
remote: - commit: 40e3c6c07ca483573ea5077acb6d6d4426c0ef9a
remote: path: tlogin/alioss.go:29
remote:
remote: (?) To push, remove secret from commit(s) or follow this URL to allow the secret.
remote: https://github.com/AbnerEarl/goutils/security/secret-scanning/unblock-secret/2gU79tijxacDeMrROeRocrk4cOD
remote:
remote:
remote: —— Alibaba Cloud AccessKey Secret ————————————————————
remote: locations:
remote: - commit: 40e3c6c07ca483573ea5077acb6d6d4426c0ef9a
remote: path: tlogin/alioss.go:32
remote:
remote: (?) To push, remove secret from commit(s) or follow this URL to allow the secret.
remote: https://github.com/AbnerEarl/goutils/security/secret-scanning/unblock-secret/2gU79tHxe6gzcQtzAzJvcAjXdnM
remote:
remote:
remote:
error: failed to push some refs to ‘https://github.com/AbnerEarl/goutils.git’


解决方法,这里有三种方法:

1)删除代码里面的定义的 secret 相关的值,重新commit,再push。

2)修改仓库的配置关闭secret检测,步骤如下:

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

3)通过 push 提示给出的访问链接进行许可添加,步骤如下:

在这里插入图片描述

在这里插入图片描述

最后,再次 push 就可以了。

  • 19
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
当你在使用git push命令时,如果出现错误提示"! [remote rejected] master -> master (pre-receive hook declined)",这通常是由于远程仓库的钩子(pre-receive hook)拒绝了你的推送引起的。钩子是一些在特定事件发生时自动执行的脚本,它们可以用来验证和控制提交到远程仓库的内容。 要解决这个问题,你可以尝试以下几种方法: 1. 检查你的代码:首先,你应该检查你的本地代码是否有错误或不规范的内容。确保你的代码符合项目的规范,并且没有任何语法错误或其他问题。 2. 检查远程仓库的钩子:联系项目经理或仓库管理员,确认远程仓库是否有设置钩子来验证提交。如果有,你可以询问他们有关钩子的具体规则和要求。 3. 检查分支权限:确保你具有向远程仓库的master分支推送代码的权限。有时,项目经理或仓库管理员可能会限制对某些分支推送权限。如果你没有相应的权限,你需要与他们沟通并请求相应的权限。 4. 提交到新分支:如果你无法向master分支推送代码,你可以尝试创建一个新的分支并将代码提交到该分支。这样,你就可以在没有权限问题的情况下将代码推送远程仓库。 总结起来,当你在使用git push命令时遇到"! [remote rejected] master -> master (pre-receive hook declined)"错误时,你可以检查代码、钩子、分支权限以及尝试将代码提交到新分支解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Git发现git push origin master 报错的解决方法](https://download.csdn.net/download/weixin_38743602/14092211)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [git-push-each:git push-reach -- 将每个提交推送到自己的分支](https://download.csdn.net/download/weixin_42116847/19396390)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [git push解决办法: ! [remote rejected] master -> master (pre-receive hook declined)](https://blog.csdn.net/weixin_39818813/article/details/129591891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码讲故事

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值