Troubleshooting "fatal: reference is not a tree" Error in CircleCI Builds

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:

 
yaml
steps:
  - run:
      name: Wait for GitHub propagation
      command: sleep 20
  - checkout

This 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:

 
yaml
steps:
  - checkout
  - run:
      name: Fetch full history
      command: git fetch --unshallow

Solution 3: Retry the Checkout Step

Add retry logic to the checkout step:

 
yaml
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
        done

 

Outcome:

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

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.