Skip to content

Instantly share code, notes, and snippets.

@abdul-alhasany
Created June 20, 2024 14:05
Show Gist options
  • Save abdul-alhasany/cde58bd6c25aefced74dfbb0f42a6003 to your computer and use it in GitHub Desktop.
Save abdul-alhasany/cde58bd6c25aefced74dfbb0f42a6003 to your computer and use it in GitHub Desktop.
Add git submodule using sparse-checkout

Clone project with history only

cd <main-project-folder>

git clone --filter=blob:none --no-checkout --depth 1 --sparse <project-url>

Do sparse checkout

cd <folder-from-git-clone>

git sparse-checkout add <folder1> <folder2> ...

git checkout

Add to submodule

cd <main-project-folder>

git submodule add <project-url> <folder-from-git-clone>

You should see a message

Adding existing repo at '<folder-from-git-clone>' to the index

Updating submodule

git submodule update <folder-from-git-clone>

Reference

https://stackoverflow.com/a/63786181/529024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment