Resolving a blocked push
To resolve a blocked push, you must remove the secret from all of the commits it appears in.
- If the secret was introduced by your latest commit, see Removing a secret introduced by the latest commit on your branch.
- If the secret appears in earlier commits, see Removing a secret introduced by an earlier commit on your branch.
Removing a secret introduced by the latest commit on your branch
- Remove the secret from your code.
- To commit the changes, run
git commit --amend --all. This updates the original commit that introduced the secret instead of creating a new commit. - Push your changes with
git push.
Removing a secret introduced by an earlier commit on your branch
-
Examine the error message that displayed when you tried to push your branch, which lists all of the commits that contain the secret.
remote: —— GitHub Personal Access Token —————————————————————— remote: locations: remote: - commit: 8728dbe67 remote: path: README.md:4 remote: - commit: 03d69e5d3 remote: path: README.md:4 remote: - commit: 8053f7b27 remote: path: README.md:4 -
Next, run
git logto see a full history of all the commits on your branch, along with their corresponding timestamps.test-repo (test-branch)]$ git log commit 8053f7b27 (HEAD -> main) Author: Octocat <1000+octocat@users.noreply.github.com Date: Tue Jan 30 13:03:37 2024 +0100 my fourth commit message commit 03d69e5d3 Author: Octocat <1000+octocat@users.noreply.github.com> Date: Tue Jan 30 13:02:59 2024 +0100 my third commit message commit 8728dbe67 Author: Octocat <1000+octocat@users.noreply.github.com Date: Tue Jan 30 13:01:36 2024 +0100 my second commit message commit 6057cbe51 Author: Octocat <1000+octocat@users.noreply.github.com Date: Tue Jan 30 12:58:24 2024 +0100 my first commit message -
Focusing only on the commits that contain the secret, use the output of
git logto identify which commit comes earliest in your Git history.- In the example, commit
8728dbe67was the first commit to contain the secret.
- In the example, commit
-
Start an interactive rebase with
git rebase -i <COMMIT-ID>~1.- For
<COMMIT-ID>, use the commit identified in step 3. For example,git rebase -i 8728dbe67~1.
- For
-
In the editor, choose to edit the commit identified in step 3 by changing
picktoediton the first line of the text.edit 8728dbe67 my second commit message pick 03d69e5d3 my third commit message pick 8053f7b27 my fourth commit message -
Save and close the editor to start the interactive rebase.
-
Remove the secret from your code.
-
Add your changes to the staging area using
git add ..Hinweis
The full command is
git add .:- There is a space between
addand.. - The period following the space is part of the command.
- There is a space between
-
Commit your changes using
git commit --amend. -
Run
git rebase --continueto finish the rebase. -
Push your changes with
git push.
Bypassing push protection
Hinweis
If you don't see the option to bypass a block, you should remove the secret from the commit, or submit a request for "bypass privileges" in order to push the blocked secret. See Requesting bypass privileges.
-
Rufe die URL, die von GitHub zurückgegeben wurde, als dein Push blockiert wurde, als dieselbe benutzende Person auf, die den Push durchgeführt hat. Wenn eine andere Peson versucht, diese URL aufzurufen, wird ein
404-Fehler zurückgegeben. -
Wähle die Option aus, die am besten beschreibt, warum du in der Lage sein solltest, den geheimen Schlüssel zu pushen.
-
Wenn das Geheimnis nur in Tests verwendet wird und keine Bedrohung darstellt, klicke auf It's used in tests (Wird in Tests verwendet).
-
Wenn die erkannte Zeichenfolge kein Geheimnis ist, klicke auf It's a false positive (Es handelt sich um einen False Positive).
-
Wenn das Geheimnis echt ist, du es jedoch später beheben möchtest, klicke auf I'll fix it later (Problem wird später behoben).
Hinweis
Du musst einen Grund für die Umgehung des Pushschutzes angeben, wenn das Repository die Geheimnisüberprüfung aktiviert hat.
Beim Pushen in ein öffentliches Repository, für das die Geheimnisüberprüfung nicht aktiviert ist, sind Sie dank Pushschutz für Benutzer, der standardmäßig für Ihr Benutzerkonto aktiviert ist, weiterhin vor versehentlichem Pushen von Geheimnissen geschützt.
Mit dem Pushschutz für Benutzer blockiert GitHub automatisch Pushvorgänge in öffentliche Repositorys, wenn diese Pushvorgänge unterstützte Geheimnisse enthalten, aber Sie müssen keinen Grund für die Zulassung des Geheimnisses angeben, und GitHub generiert keine Warnung. Weitere Informationen finden Sie unter Verwalten des Pushschutzes für Benutzer.
-
-
Click Allow me to push this secret.
-
Reattempt the push on the command line within three hours. If you have not pushed within three hours, you will need to repeat this process.
Requesting bypass privileges
-
Rufe die URL, die von GitHub zurückgegeben wurde, als dein Push blockiert wurde, als dieselbe benutzende Person auf, die den Push durchgeführt hat. Wenn eine andere Peson versucht, diese URL aufzurufen, wird ein
404-Fehler zurückgegeben. -
Fügen Sie unter „Oder Überbrückungsberechtigungen anfordern“ einen Kommentar hinzu. Sie können z. B. erklären, warum Sie glauben, dass die Weitergabe des Geheimnisses sicher ist, oder den Kontext der Anforderung zur Überbrückung der Sperre erläutern.
-
Klicken Sie auf Anforderung übermitteln.
-
Prüfen Sie Ihre E-Mail-Benachrichtigungen auf eine Antwort auf Ihre Anforderung. Nachdem Ihre Anforderung überprüft wurde, erhalten Sie eine E-Mail, die Sie über die Entscheidung informiert.
- If your request is approved, you can push the commit (or commits) containing the secret to the repository, as well as any future commits that contain the same secret.
- If your request is denied, you need to remove the secret from all commits before pushing again. For information on how to remove a blocked secret, see Resolving a blocked push.