The secret is in an earlier commit of the same push
CommonYou committed the credential, noticed, removed it, and committed the removal. Both commits are unpushed, so both are in the push, and the first still contains the secret. Nothing about the second commit removes it from the first — git history is append-only until you rewrite it.
Confirm
git log --oneline origin/<branch>..HEAD
More than one commit waiting to be pushed. The refusal names a SHA — check whether it is the tip or one behind it
Fix
- If the secret is confined to commits not yet pushed anywhere, rewrite them: an interactive rebase to edit the offending commit (
git rebase -i <COMMIT-ID>~1, the method GitHub documents), or a soft reset to the merge base with the remote and one clean commit. - Confirm afterwards that the secret is absent from every commit in the range, not just from the working tree.
- Rotate the credential regardless. It existed in a commit; treat it as exposed.
git reset --soft "$(git merge-base HEAD origin/<branch>)" git diff --cached # the secret must not appear here, and nothing you did not change should show as deleted; fix the file and git add it git commit -m 'clean commit without the secret'
Collapses unpushed commits into one, letting you stage a version with no secret. Only safe while the commits have not been pushed or shared.