No matter what I do, I can't push to my repository. Simple learning code. Getting To https://github.com/{repository} ! [remote rejected] main -> main (push declined due to repository rule violations) error: failed to push some refs to {repository} #158212
-
|
So I have deleted repository, even deleted my personal GitHub account and recreated, not avial. I even Chat GPT usinfg explectives at this point. Help! To https://github.com/cunhajo-code/nodejs-express-mongodb-bootcamp.git I get the following message EVERY TIME it try to push to a repository with this simple learning code from a Udemy course. WHy? WHat Am I doing wrong . An entire day with Open AI helping, still getting this nonsense. I have used github before, not an expert, but this makes me want to go drive an uber! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
hey @cunhajo-code here are the steps you can check The Problem: GitHub Security RulesTurns out GitHub now blocks pushes that look like you're committing sensitive data, even if it's obviously fake stuff from a tutorial. In my case, the code had a hardcoded JWT secret like this: const jwtSecret = 'mysecretkey';That alone was enough for GitHub to block the push due to secret scanning rules. No detailed error message. Just... "push declined." The FixHere’s what finally worked for me: 1. Remove or Hide the SecretsChange hardcoded secrets to use environment variables: const jwtSecret = process.env.JWT_SECRET;Then put your secrets in a echo ".env" >> .gitignore2. Check Branch Protection RulesIf you're pushing to the
git checkout -b dev
git push origin dev3. Force Push if You've Rewritten HistoryIf you've removed secrets from history using something like git push origin main --force |
Beta Was this translation helpful? Give feedback.
-
|
Same here, if I took the time to read the message, I would have found the offending file. Once I understood the issue was secrets github refused to archive, I was able to compile an appropriate gitignore. Thanks All!
From: rossmacrae ***@***.***>
Sent: Tuesday, May 13, 2025 5:40 AM
To: community/community ***@***.***>
Cc: cunhajo-code ***@***.***>; Mention ***@***.***>
Subject: Re: [community/community] No matter what I do, I can't push to my repository. Simple learning code. Getting To https://github.com/{repository} ! [remote rejected] main -> main (push declined due to repository rule violations) error: failed to push some r
Thanks @AyushSingh360 <https://github.com/AyushSingh360> this helped me, I had the same issue. I'd also failed to notice that higher up in the error message github had highlighted the the offending file and the line with the 'secret' in it. I'm also a novice git user: there were some hoops to jump through to force a new commit to git after making the required changes. But in the end it got done.
—
Reply to this email directly, view it on GitHub <#158212 (reply in thread)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/BSCWP4TQYWIF5CULIV327JT26G4XJAVCNFSM6AAAAAB4KUMIPWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGMJSHEYDINY> .
You are receiving this because you were mentioned. <https://github.com/notifications/beacon/BSCWP4UVHVMBY6XSIKSLUCL26G4XJA5CNFSM6AAAAAB4KUMIPWWGG33NNVSW45C7OR4XAZNRIRUXGY3VONZWS33OINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAZBKVO.gif> Message ID: ***@***.*** ***@***.***> >
|
Beta Was this translation helpful? Give feedback.
hey @cunhajo-code here are the steps you can check
The Problem: GitHub Security Rules
Turns out GitHub now blocks pushes that look like you're committing sensitive data, even if it's obviously fake stuff from a tutorial.
In my case, the code had a hardcoded JWT secret like this:
That alone was enough for GitHub to block the push due to secret scanning rules. No detailed error message. Just... "push declined."
The Fix
Here’s what finally worked for me:
1. Remove or Hide the Secrets
Change hardcoded secrets to use environment variables:
Then put your secrets in a
.envfile and add.envto.gitignore: