🔀 Git: Fix a Shallow Clone Rejected by a Branch Protection Rule
A shallow clone (–depth N) deliberately holds an incomplete history – only the most recent N commits exist locally as real objects, with everything older collapsed into a synthetic ‘grafted’ boundary instead of actual commit data. A protected-branch rule that depends on walking history – requiring a verified or signed-commit chain back to a known point, or a linear-history check – can fail specifically because the shallow clone’s history doesn’t contain the ancestry the server-side rule needs to walk, even though the push itself succeeds in uploading every actual commit object just fine; the rejection comes entirely from how much history the local clone happened to carry, with nothing wrong with the change being pushed at all.
🔎 The Problem
git clone --depth 1 git@host:org/repo.git # ... make a commit, then: git push origin feature/payment-retry # ! [remote rejected] feature/payment-retry -> feature/payment-retry # (required status check "history-verification" could not find # enough commit history to validate this push) # The diff itself is fine - the clone just never had the ancestry # the server-side rule needed to walk
✅ The Fix
- Run git fetch –unshallow before pushing to any protected branch whose rules depend on history (signed-commit chains, linear-history checks), converting the local clone into a full one so the server has complete ancestry to validate against.
- In CI specifically, check whether the checkout step defaults to a shallow clone (many default to depth 1 for speed) and set an explicit deeper fetch-depth, or fetch-depth: 0, for any pipeline that needs to push to or validate against a history-dependent protected branch.
- Read the server’s rejection message carefully before assuming it’s a permissions problem – a shallow-history failure can look superficially similar to an unrelated status-check or access failure if you only skim the error text.
🚨 Why This Is Dangerous
A pipeline that usually pushes successfully and only fails this way occasionally – exactly when the shallow depth doesn’t happen to reach far enough back for a particular rule – reads as a frustrating, intermittent failure, even though the real cause is completely deterministic once clone depth, not push content, is what gets checked.
A shallow clone is complete enough to work with – until a protection rule on the other end needs history your clone was never given in the first place.




