Problem
The error "fatal: reference is not a tree" occurs during the checkout step when CircleCI cannot find the commit SHA in the local repository. This occurs when builds begin before GitHub has finished propagating the new commit SHA.
Why this occurs: CircleCI builds triggered immediately after a push may start before GitHub's systems fully propagate the commit reference, causing the checkout step to fail.
Solutions
Solution 1: Add a Delay Before Checkout
Add a short delay before the checkout step to allow GitHub time to propagate the commit:
steps:
- run:
name: Wait for GitHub propagation
command: sleep 20
- checkoutThis 20-second delay gives GitHub time to update its references before CircleCI attempts to checkout the commit.
Solution 2: Use a Full Clone Instead of a Shallow Clone
Disable shallow cloning to fetch the complete repository history:
steps:
- checkout
- run:
name: Fetch full history
command: git fetch --unshallowSolution 3: Retry the Checkout Step
Add retry logic to the checkout step:
steps:
- run:
name: Checkout with retry
command: |
for i in {1..3}; do
git fetch origin && git checkout $CIRCLE_SHA1 && break
echo "Retry $i failed, waiting..."
sleep 10
doneOutcome:
After implementing one of these solutions:
Builds succeed: The delay allowed GitHub to propagate the commit SHA before checkout.
Builds still fail: The issue may be with GitHub's service. Check GitHub Status for any ongoing incidents or contact GitHub support.
Additional Resources
- CircleCI Checkout Step Documentation - Understanding the checkout step
- GitHub Webhooks Documentation - How webhooks trigger builds
- GitHub Status - Check for GitHub service issues
- CircleCI Discuss Forum - Community support
Comments
Article is closed for comments.