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, or a soft reset to before it 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 origin/<branch> && git restore --staged <file> && 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.