gitshallow-clone

git shallow clone *several* specific refs (commits), *which are not branches*


For my specific use case, I only need a shallow git clone that contains just two specific commits, and nothing else (no remaining history, no other branches).

Here are some things I tried:

What's the correct way to fetch exactly n commits and nothing else?


Solution

  • Instead of cloning, the solution is to init an empty git repo, and fetch each ref one-by-one with --depth 1:

    mkdir FOLDER_NAME
    cd FOLDER_NAME
    git init
    git remote add origin GIT_URL
    git fetch --depth 1 origin REF1
    git fetch --depth 1 origin REF2