Checkout code error: reference is not a tree

We keep getting the same error during the “Checkout code” step since this morning

git version 2.36.1
Cloning git repository
Cloning into '.'...
remote: Enumerating objects: 3750, done.        
remote: Counting objects: 100% (531/531), done.        
remote: Compressing objects: 100% (217/217), done.        
remote: Total 3750 (delta 368), reused 396 (delta 297), pack-reused 3219        
Receiving objects: 100% (3750/3750), 993.33 KiB | 19.87 MiB/s, done.
Resolving deltas: 100% (2051/2051), done.
Fetching from remote repository
remote: Enumerating objects: 168, done.        
remote: Counting objects: 100% (168/168), done.        
remote: Compressing objects: 100% (74/74), done.        
remote: Total 168 (delta 96), reused 156 (delta 84), pack-reused 0        
Receiving objects: 100% (168/168), 134.68 KiB | 722.00 KiB/s, done.
Resolving deltas: 100% (96/96), completed with 20 local objects.
 * [new ref]         refs/pull/242/head -> origin/pull/242
Checking out branch
fatal: reference is not a tree: 42afa3319c2acc131b7cdb48aa1b4d77c4032a18

exit status 128

It’s happening on multiple PRs.

Edit: We just merged a PR in main and we don’t get the error when running CI on main. However, we still have the error on PRs.

The error suggested that it could be one, or many/all of the following, in order by what I think is most likely:

  • The git SHA is no longer available in the branch that is being referenced so when the checkout runs it is unable to locate the reference.
  • The current deploy key used is not allowed to checkout the branch or the git commit.

I would recommend trying to run the same command locally against the SHA to check if you are able to complete the clone to rule out the first option.

In regards to the second bullet point, I would recommend making sure that the SSH key that is set as your deploy key is generated in the right format following the guide below:

Kind Regards
Owen Oliver

Hi Owen,
Thanks for your answer. The issue seemed to have resolved itself back in September. However, we are seeing the same error today.

After waiting a while, hitting the “Retrying the workflow from failed” button starts to work for some reason… like if GH and CCI are “”“out-of-sync”“”.

We didn’t change our CircleCI/GH configuration lately.


We have also suddenly gotten this error since yesterday, without changing anything to the config.

The error “fatal: reference is not a tree:” is being generated by git as it processes data that it has received from github and so is out of circleci’s control/hands.

One thing to look at - are you caching the git rep in some way so that the git command being issued by circleci is trying to update a local repo rather than generate a new local repo. If so delete the cached repo copy so that it has to be rebuilt. The reason for doing this can be seen on this thread for another CI system.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.