Resolving the Git Error: git cherry-pick bad object

Greg Foster
Greg Foster
Graphite software engineer

The git cherry-pick bad object error typically arises when Git cannot find the commit you're trying to cherry-pick.

This guide provides step-by-step instructions to troubleshoot and resolve this issue.

The git cherry-pick command is used to apply the changes introduced by one or more commits from a different branch onto the current branch. The error message fatal: bad object essentially means Git is unable to locate the commit hash you've specified for cherry-picking. This can happen for several reasons:

  • The commit hash is incorrect or mistyped.

  • The commit exists in a remote repository but hasn't been fetched to your local repository.

  • The commit is in a branch that you haven't checked out or fetched into your local repository.

  • Double-check the commit hash: Ensure the commit hash you're using in the git cherry-pick command is correct. A simple typo can lead to the bad object error.
  • Fetch updates from the remote repository: If the commit exists in a remote repository, you may need to fetch the updates:
Terminal
git fetch origin

Replace origin with the name of your remote. This command updates your local copy of the remote repository but doesn't merge any changes into your working branch.

  • Check if the commit is in the fetched data: Use the following command to search for the commit in all branches, including those fetched from the remote:
Terminal
git log --all --grep="commit message"

Replace "commit message" with a unique part of the commit message. If you find the commit, ensure you have the correct hash.

If you know which branch the commit is on, you can fetch that specific branch:

Terminal
git fetch origin branch-name:branch-name

Replace branch-name with the name of the branch containing the commit. This command fetches the branch from the remote named origin and updates (or creates) a local branch with the same name.

Once you've confirmed the commit exists in your local repository, attempt the cherry-pick operation again using the correct commit hash:

Terminal
git cherry-pick commit-hash

Replace commit-hash with the correct hash of the commit you wish to cherry-pick.

  • Using the correct repository: Verify you're working in the correct local repository that should contain the commit.

  • Ensuring branch existence: If the commit is on a branch that doesn't exist locally, you'll need to fetch or pull that branch from the remote.

If after following these steps you are still unable to resolve the bad object error, please see the official git documentation on git cherry-pick.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2