19/11/2026 00:00am

git push blocked because of a secret? What GitHub push protection is and how to fix it
#push protection
#secret scanning
#GitHub
#Git
#Octoverse 2026
Picture this: you have worked all day, you type git push with a sigh of relief, and the terminal replies that your push was rejected. GitHub found something that looks like a secret in the code you were about to send.
The feature behind this is called push protection, and the Octoverse 2026 report says it ran billions of times this year. Today Superdev Academy walks through what it is, who it affects, what to do in order once you are blocked, and why removing the secret from only your latest commit is usually not enough.
What is push protection
According to GitHub's About push protection documentation, this is a secret scanning feature designed to prevent hardcoded credentials. It blocks a push that contains a secret before the secret reaches the repository, instead of alerting you after it has already leaked.
When a push is blocked, GitHub shows a message explaining why. The documentation does not show a sample of the real message, so we do not reproduce one here. Rely on the message you see on your own machine.
Who gets blocked
The documentation describes two levels. The first is user push protection, which is on by default and works on GitHub.com only. It stops you from pushing a secret to a public repository, and it does not create an alert when someone bypasses it unless the repository also has the second level turned on.
The second level is repository push protection, which is off by default. It needs GitHub Secret Protection and is turned on by an administrator at the repository, organization or enterprise level to block secret pushes into the repositories they choose.
On the scale of use, Octoverse 2026 says push protection ran 5.8 billion scans, almost four times the pace of 2025. That figure is the number of scans, not the number of secrets blocked. It only tells you the feature is used very widely, and it should not be read as a leak rate. Source: the Octoverse 2026 report.
What to do, in order, once you are blocked
The documentation gives the fix briefly: review the code it points to, remove the secret, then push again. In practice there is one stumbling block that beginners hit often, so we expand it into steps.
Step 1: Find which commit holds the secret
Use git log -S to search history for a piece of the secret. This example uses a fake value for teaching.
git log -S"fake-demo-value" --onelineOur team ran this in a practice repo where a fake value was added in one commit and removed in the next. The command listed both commits, the one that added the value and the one that removed it. This is why fixing only the latest commit is not enough: the older commit still holds that text in the history you are about to push.
Step 2: Rewrite the history you have not pushed yet
If those commits have never been pushed, you can rewrite them. A simple way is to step the commits back with git reset --soft and commit again without the secret.
git reset --soft HEAD~2
git commit -m "add config (clean)"In our experiment, after doing this, git log -S"fake-demo-value" --oneline found no commit at all (the 2 in HEAD~2 is the number of commits to step back, so adjust it to match yours). If only the latest commit needs fixing, git commit --amend works.
Step 3: Rotate the secret if it has left your machine
If the secret was ever pasted into a chat, sent to another remote or pushed to a public repo, treat it as leaked and always issue a new value (rotate). Deleting it from history does not remove the old value from the places it has already reached.
Step 4: Push again
git pushCan you bypass it
In some cases, and with care. For repository push protection, the documentation says people with write access can bypass it by choosing a reason. There are three: "It's used in tests" closes the alert as used in tests, "It's a false positive" closes it as wrongly detected, and "I'll fix it later" leaves the alert open.
Every bypass creates an alert in the Security and quality tab, is recorded in the audit log and sends an email to the relevant owners or administrators. The delegated bypass level also lets you set who can approve other people's bypass requests. If what was blocked is a real secret, the right move is to remove it and rotate it, not to bypass.
But mine is only a test value, why block it
That is an understandable feeling, and such cases exist. The "It's used in tests" and "It's a false positive" options in the documentation are there for exactly this reason.
But the system checks the pattern of the text and cannot tell whether a value is real or a test. If your team often has test values that look like real keys, keep them in a file that Git does not track and read them from an environment variable. That is calmer than bypassing every time.
Prevent it from the start
The most effective habit is to never let a secret sit in a folder Git tracks in the first place. Create a .env file for secrets, add .env to .gitignore, and check that Git really ignores it with this command.
git check-ignore -v .envIf it prints a line that points to .gitignore, the file is being ignored. In code, read values from environment variables instead of writing them in directly. For authenticating with GitHub without embedding a token in a command, we wrote about it in SSH Key for GitHub.
Summary: remove it from the whole history, then rotate what leaked
GitHub push protection blocks a push that contains a secret before it reaches the repository. User push protection is on by default on GitHub.com for public repos, while the repository level needs an administrator to turn it on. When you are blocked, search with git log -S to find which commit holds the secret, rewrite the unpushed history so it is gone, rotate the value if it ever left your machine, and then push.
To get ready before it happens to you, create a practice repo, add one fake value, and rehearse the search and the history rewrite from the steps above until they feel easy. When the day comes, you will fix it in a few minutes.
If you want to get fluent with branches, Pull Requests and code review, take a look at the Git & GitHub Essentials course from Superdev Academy. It runs 2 hours across 42 lessons, is taught in Thai, and comes with course materials and a certificate, with 12 months of access. It covers everyday Git and GitHub fundamentals, not push protection specifically. Browse all courses at learn.superdevacademy.com/courses.
🎯 Follow dev knowledge from Superdev Academy:
🔵 Facebook: Superdev Academy Thailand
🎬 YouTube: Superdev Academy Channel
📸 Instagram: @superdevacademy
🎬 TikTok: @superdevacademy
FAQ: Frequently Asked Questions about This Article
A collection of questions and answers to help you better understand the content of this article.