Programming involves change and managing that change is the only way to make sense of it. You’ll learn about submodules in this episode and how that enables you to reference code from other repositories.
There’s a concept in programming called refactoring. I could spend several episodes about this one topic and will in future episodes. For now though, I’ll just say that you normally don’t want to repeat code. In other words, you don’t want similar or even the same source code spread out in multiple places in your project. That’s because if you ever need to change this code or fix a bug, then you need to make sure to change each location. It’s too easy to miss places.
If instead that code was in a single place, and exposed as a class or even just a single method, then it can still be used in multiple places. But the code itself is now in a single place. Any changes or bug fixes can be made directly to the one spot.
That’s a great way to design code to be reused throughout your project. It can be so useful that you might find yourself wanting to use the code in other projects too. Then what do you do?
What you need is a way to use code from another repo inside your own repo. And Git has two options available for you. Listen to the full episode to learn about Git subtrees and Git submodules and why I prefer submodules.