Search code examples
gitgit-submodules

"fatal: remote error: upload-pack: not our ref" error when fetching git submodules


Scenario

I am trying to setup torch-mlir repository on my personal server. This repository has two submodules, llvm-project and mlir-hlo.

Now, on my server, I already have llvm-project and mlir-hlo. However, I am unable to replace the links for these submodules in the torch-mlir project.


What I've tried

  1. Cloned torch-mlir locally
  2. replaced the urls of the submodules in the .gitmodule file
  3. used the command: git submodule deinit
  4. went inside the externals/llvm-project and externals/mlir-hlo and executed the following commands respectively:
    1. git remote set-url origin <my server path to llvm-project>
    2. git remote set-url origin <my server path to mlir-hlo>
  5. Back at project root, executed git submodule sync
  6. now executed, git submodule update --init --recursive

I am receiving the following error:

fatal: remote error: upload-pack: not our ref <aHash>
fatal: the remote end hung up unexpectedly
Fetched in submodule path 'externals/mlir-hlo', but it did not contain <aHash>. Direct fetching of that commit failed.

This commit hash does not even exist in the original github.com repo for mlir-hlo.

What is the correct way of replacing the submodules so that it works?


Solution

  • I ended up doing the following (resulted in a successful setup and build):

    I moved under the torch-mlir directory and executed the following steps.

    Step 1: Remove the existing submodules

    Check the current status of sub-modules:

    git submodule status
    

    We wish to remove these, since they are linked to the github.com links:

    git rm -r --cached externals/mlir-hlo
    git rm -r --cached externals/llvm-project
    rm -rf externals/llvm-project; rm -rf  externals/mlir-hlo;
    

    This will remove the submodules and their cached indices.

    Step 2: Add the local submodule config

    First, update the link to submodule repositories:

    nano .gitmodules
    

    Now, ensure the links are thoroughly updated:

    git submodule add --force <your server path to mlir-hlo>.git externals/mlir-hlo
    
    git submodule add --force <your server path to llvm-project>.git externals/llvm-project
    

    The above commands will download the repositories and place them in the submodule's respective path.

    For each submodule, select the particular branch (on your server's repo):

    git submodule set-branch --branch main externals/mlir-hlo
    git submodule set-branch --branch release/16.x externals/llvm-project
    

    Ensure all submodules are synced up:

    git submodule update --init --recursive
    

    After this, we can go ahead and build the torch-mlir project as per the documentation for that project.