How to connect two separate GitHub repositories together

I need help with connecting two different GitHub repositories. Both repos are private and I want to use code from one repository inside another repository.

Basically, I have two separate projects. One project needs to use the other project, but I don’t want to copy all the files from the first repo into the second one. That would be messy and doesn’t make sense since these are different tools that should stay separate.

What would be the best approach to handle this situation? I’m looking for a simple solution that works well with GitHub.

Package management could work well here, depending on your stack. With Node.js, you can publish the first repo as a private npm package and install it in the second project. GitHub Packages handles private registries and works seamlessly with your existing repos. This treats your shared code like a real dependency with proper versioning - updates become way more controlled. I’ve done this with internal libraries and it’s great when you’re sharing code across multiple projects. You’ll need to set up package.json and auth, but once it’s running, updates are much cleaner than copying files around.

you could also try git subtree - it’s way simpler than submodules. just run git subtree add --prefix=folder-name repo-url branch-name and it pulls the other repo into a subfolder. way less headache than submodules and no dealing with recursive clone nonsense.

Git submodules are an effective way to link two separate repositories without merging them. You can add a repository as a submodule by executing git submodule add <repository-url>. This maintains the independence of both projects while establishing a connection. Remember, whenever you clone the main repository, you will need to run git submodule update --init --recursive to fetch the submodule content. Although there’s a bit of a learning curve due to the need for separate commits in each repository, it simplifies dependency management in the long run.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.