← Back to all articles

Engineering / Guide

Managing Multi-Repository Dependencies with Git Submodules and Symlinks

A pragmatic guide to sharing code across multiple repositories using Git submodules, recursive cloning, and symlinking packages for local development.

**Refference: **

Key Command:

Git Submodule

Let’s say you’re working on a project called Slingshot. You’ve got code for y-shaped stick and a rubber-band. At the same time, in another repository, you’ve got another project called Rock—it’s just a generic rock library, but you think it’d be perfect for Slingshot. You can add rock as a submodule of slingshot. In the slingshot repository:

git submodule add https://github.com/<user>/rock rock

At this point, you’ll have a rock folder inside slingshot, but if you were to peek inside that folder, depending on your version of Git, you might see … nothing.

Newer versions of Git will do this automatically, but older versions will require you to explicitly tell Git to download the contents of rock:

git submodule update --init --recursive

If everything looks good, you can commit this change and you’ll have a rock folder in the slingshot repository with all the content from the rock repository.

On the command line, Git commands issued from slingshot (or any of the other folders, rubber-band and y-shaped-stick) will operate on the “parent repository”, slingshot, but commands you issue from the rock folder will operate on just the rock repository:

cd ~/projects/slingshot
git log # log shows commits from Project Slingshot
cd ~/projects/slingshot/rubber-band
git log # still commits from Project Slingshot
cd ~/projects/slingshot/rock
git log # commits from Rock

Create React Symbolic Link:
ref: https://ismayilkhayredinov.medium.com/symlinking-react-libraries-for-local-development-bcecef2a4d01