How to Fix Git’s “Fatal: Remote Error: Not Our Ref”

Git’s fatal: remote error: upload-pack: not our ref means the remote cannot or will not provide the object ID Git requested, usually because the commit was never pushed, the wrong repository is being queried, or the commit is no longer available through an accessible reference. The fix is to identify the failing repository and requested commit, then correct the remote, publish the missing commit, or update an obsolete revision. Match the failure to these symptoms before changing anything.

Symptom Likely Cause Appropriate Fix
Failure during a submodule update The parent repository references a commit unavailable in the submodule’s remote Publish the pinned commit or commit an intentional replacement in the parent repository
Failure after a force-push or branch deletion A checkout or CI job still requests an old commit Restore an accessible reference to the commit or update the requested revision
Failure after changing repositories or moving a build environment The fetch URL points to the wrong repository or fork Correct the URL in the repository actually failing
A named branch fetch works, but fetching a commit ID fails The server restricts requests for unadvertised objects Fetch an accessible branch or tag containing the commit
A historical checkout fails in a shallow CI workspace Required history was not downloaded, or the saved revision is obsolete Check whether the commit remains reachable before expanding the clone’s history

What Git’s “Not Our Ref” Error Means

A typical message looks like this, with an actual object ID in place of MISSING_SHA:

fatal: remote error: upload-pack: not our ref MISSING_SHA

Git’s remote-side upload service is rejecting a request for a particular object, usually a commit. Despite the wording, the problem is not necessarily a missing branch name.

A ref is a named reference, such as a branch or tag, that points to an object. A commit ID identifies the commit itself. A server can advertise branch tips while refusing requests for other object IDs, depending on repository visibility and server policy.

Common reasons include:

  • A developer committed a submodule change locally but did not push it.
  • A parent repository or build job retained a commit ID after its branch was rewritten.
  • The commit exists in a different fork or remote.
  • The server has the object but does not permit fetching it through the requested route.
  • A shallow or narrowly configured checkout has not downloaded the required history.

A force-push does not immediately erase the old commit object. However, it can remove the reference that made the commit accessible; subsequent cleanup may remove the unreachable object.

A commit existing somewhere is not enough: the failing client must be able to retrieve it from the repository and identity it actually uses.

This is different from “not a git repository,” which concerns your local working directory, and “remote origin already exists,” which concerns a duplicate remote name. Initializing another repository or removing and recreating origin is not the appropriate default fix.

How to Fix Git’s “Not Our Ref” Error

The examples use origin as the remote. Replace uppercase placeholders with your actual values, without adding angle brackets.

Run commands in the repository that failed. For a submodule error, that may be the submodule rather than the parent project.

Step 1: Identify the Requested Commit and Failing Repository

  1. Identify the failing repository and operation from the error and the log lines immediately before it. Record the rejected object ID, remote URL, and command that triggered the failure.
  2. Check the working tree:
    git status
  3. Inspect the configured fetch and push URLs:
    git remote -v

Pay attention to which operation failed. A normal branch fetch, a recursive submodule update, and a CI checkout of an exact commit can request different objects from different repositories.

Commit or back up uncommitted work before switching revisions or replacing a workspace. A failed fetch is not a reason to delete the repository.

Step 2: Verify the Remote URL and Accessible References

  1. Verify that the configured fetch URL points to the repository or fork expected to contain the requested commit. Check the owner, project name, and fork, not just whether the host is correct.
  2. If the URL is wrong, update it:
    git remote set-url origin CORRECT_REPOSITORY_URL
  3. Ask the remote which references it exposes to your current credentials:
    git ls-remote origin

A successful response confirms that you can list the remote’s advertised references. If the command fails with an authentication or repository-access error, resolve that access problem before diagnosing the missing commit.

Do not treat an absent SHA in this output as proof that the commit is missing. The output lists reference tips, not every commit in their history. An older commit may be available through a branch without appearing in this list.

Step 3: Fetch a Branch That Should Contain the Commit

  1. Fetch an accessible branch expected to contain the requested commit: git fetch –no-recurse-submodules origin BRANCH_NAME
  2. Fetch that branch without recursively fetching submodules:
    git fetch --no-recurse-submodules origin BRANCH_NAME
  3. Check whether the requested commit is now available locally:
    git cat-file -e 'MISSING_SHA^{commit}'

An error means the commit is not available locally.

Fetching a named branch can succeed where requesting an arbitrary object ID fails.

Local success alone does not prove the remote will serve a direct request for that SHA: the object may already have existed in your clone. Retry the original failing operation to establish whether the repair worked.

Step 4: Restore the Required Commit or Replace an Obsolete Target

If the remote URL and branch fetch are correct but the required commit remains unavailable, decide whether you must preserve that exact revision.

  1. Replace an obsolete revision in the checkout or build configuration with an approved commit on an accessible branch or tag. Trigger a new checkout using the updated revision rather than merely rerunning a job that retains the old SHA.
  2. If the exact revision is required, find a developer clone, build workspace, or backup that still contains it. In a clone of the affected repository, confirm that its push URL points to the correct remote, then check the object:
    git cat-file -e 'MISSING_SHA^{commit}'
  3. Create a new, unused recovery branch at that commit:
    git branch RECOVERY_BRANCH MISSING_SHA
  4. Publish the recovery branch:
    git push origin RECOVERY_BRANCH
  5. Confirm that the remote exposes the new branch:
    git ls-remote origin refs/heads/RECOVERY_BRANCH

Use an authorized maintainer for the push if you lack permission. Keep the recovery reference while builds or parent repositories still depend on that commit.

Finally, rerun the original failing operation using the original client’s credentials. If no clone or backup retains the exact commit, ordinary fetching cannot reconstruct it; the dependent project must adopt another available revision.

Fixing “Not Our Ref” in Git Submodules

A parent repository stores a specific commit ID for each submodule. It does not store that submodule’s commit contents, and pushing the parent does not automatically publish the child commit.

For the committed parent revision currently checked out, inspect the recorded submodule entry:

git ls-tree HEAD -- path/to/submodule

For an initialized submodule, inspect its actual remote:

git -C path/to/submodule remote -v

If the recorded commit exists only in a developer’s submodule clone, publishing a branch containing it to the correct submodule remote preserves the parent’s existing pin.

A broken submodule pin requires either making the pinned commit available or recording a deliberate replacement, not simply checking out whatever is newest.

Synchronize an Outdated Submodule URL

Use this when the checked-out .gitmodules file contains the correct URL, but the local submodule configuration still uses an older location.

  1. Confirm that .gitmodules contains the intended submodule URL, then synchronize the local submodule configuration. Synchronization can overwrite an intentional local URL override.
  2. Synchronize initialized submodules:
    git submodule sync --recursive
  3. Initialize and update the submodules:
    git submodule update --init --recursive
  4. Confirm their checked-out revisions:
    git submodule status --recursive

If .gitmodules itself points to the wrong repository, synchronizing will propagate that wrong URL. The project needs a committed URL correction, not repeated synchronization.

Replace an Unavailable Submodule Commit

Use this only when the original commit cannot be restored and the project can intentionally adopt another revision. Start on a parent-repository working branch with no unrelated changes staged, and preserve any local modifications inside the submodule.

  1. Fetch the submodule branch containing the approved replacement:
    git -C path/to/submodule fetch origin BRANCH_NAME
  2. Check out the approved commit from that fetched history:
    git -C path/to/submodule switch --detach AVAILABLE_SHA

    A detached checkout is normal for a submodule pinned to a specific commit.

  3. Stage the changed submodule pointer in the parent repository:
    git add -- path/to/submodule
  4. Commit the new pin:
    git commit -m "Update submodule to an available commit"
  5. Verify that the committed submodule configuration can be checked out:
    git submodule update --init --recursive
  6. Run the project’s relevant tests. Once the replacement is approved, publish the parent branch through the project’s normal review workflow. For a working branch pushed to the same branch name on origin:
    git push origin HEAD

The repair is complete only when a downstream checkout can retrieve the replacement and the project works with it. Updating the submodule directory without committing the parent’s pointer leaves other checkouts dependent on the old SHA.

Fixing “Not Our Ref” in CI and Shallow Clones

CI and shallow-clone failures are addressed by verifying the intended commit, checking checkout configuration, and expanding history only when the commit remains obtainable.

Stale CI Revisions and Migrated Workspaces

A CI job may request a saved commit from a webhook event, pull-request reference, pipeline parameter, or cached checkout. Retrying the job may repeat the same obsolete request.

Compare the SHA recorded in the job with the revision the job is supposed to build. If the target legitimately changed, create a new build using the approved current revision. If reproducibility requires the old commit, restore that commit’s availability rather than silently substituting a newer one.

Retrieval failures can also appear after moving a Jenkins controller to another Linux machine. Check the environment that actually performs the checkout, including any build agent:

  • The repository URL and credential identity
  • Branch and tag fetch configuration
  • Shallow-checkout settings
  • Submodule URLs
  • Reused workspaces and repository caches

A migrated workspace can expose a configuration mismatch, but migration alone does not establish the cause. Test a separate, clean workspace with the same repository URL and credentials before discarding an existing workspace that may contain useful objects.

Finish by running the job from checkout through its relevant tests. Confirm that the log shows the intended commit, not just a successful build of some other revision.

Missing History in a Shallow Clone

A shallow clone lacks some history, but that does not automatically explain a remote-side rejection. Expanding history helps only if the required commit remains obtainable from the remote.

  1. Check whether the failing repository is shallow:
    git rev-parse --is-shallow-repository
  2. If the result is true and the target belongs to history available through a known branch, request that branch without the local shallow limit:
    git fetch --unshallow --no-recurse-submodules origin BRANCH_NAME
  3. Verify the required commit:
    git cat-file -e 'MISSING_SHA^{commit}'
  4. Rerun the failed checkout or build.

If the upstream repository is itself shallow, Git can obtain only the history that upstream has. Also, expanding one branch’s history does not fetch every unrelated branch.

For a submodule failure, check whether the submodule’s own repository is shallow. Making the parent repository complete does not make its submodules complete.

When the Server Still Rejects the Commit

If a commit is present in a healthy clone but unavailable to the failing client, separate object existence from fetch permission.

Git servers can restrict requests for object IDs that are not exposed through permitted references. Hidden refs, repository permissions, and differences between user and CI credentials can therefore affect availability.

The preferable repair is usually to publish the required commit through an authorized branch or tag, or fetch an already accessible reference containing it. Do not broadly relax server object-access restrictions as a first-line workaround.

If an advertised branch itself cannot be fetched, even with submodule recursion disabled, the server may need investigation. Repository administrators should check reference visibility, object integrity, and any replicas or mirrors used to serve fetches. A reference can exist while the underlying object storage is incomplete or inconsistent.

After the administrator restores a consistent repository or corrects access, retry the named-reference fetch and the original failing operation using the affected account. A successful administrator-only fetch does not prove that CI access is repaired.

Confirm the Fix and Prevent Recurrence

Use the original failing operation as the final test. Listing refs or finding a commit locally proves only part of the path.

Confirm that:

  • The client fetched from the intended repository or fork.
  • The requested revision is the one the project actually needs.
  • A clean checkout can retrieve that revision with the required credentials.
  • Recursive submodule updates finish successfully.
  • Relevant builds or tests pass.

To prevent recurrence, publish submodule commits before publishing parent commits that reference them. Keep commits required for reproducible builds reachable through an appropriate branch or tag, and avoid rewriting shared history without coordinating dependent jobs.

Once the original checkout and tests succeed, retain any recovery reference still needed by active pins and update the project’s build configuration to use a maintainable reference strategy.

Frequently Asked Questions

Will Changing Git’s User Name or Email Fix This Error?

No. Git’s user name and email identify commit authors and committers; they do not grant access to remote objects. Remote access depends on the repository URL, authentication credentials, and server permissions.

Should I Run Git Garbage Collection to Fix “Not Our Ref”?

No. Local garbage collection does not make an unavailable remote commit fetchable. If a local clone may hold the only remaining copy of the required commit, create a reference to it and publish or back it up before attempting cleanup.

Does “Not Our Ref” Mean My Local Changes Are Lost?

No. The message identifies a failed remote object request; it does not by itself mean that your working files or local commits were deleted. Inspect the working tree and preserve local work before attempting recovery actions that change revisions or replace the checkout.