March 2021: A blog about Using Git Submodules
When you need to reuse code between projects, or make some portion of code private and let other parts be public.
Hello all!
Here’s my first recap newsletter for the month of March 2021.
My New Website Went Live
March was an exciting month for me, I launched my new website at the beginning of the month, after 11 months in the making. If you’d like to read a little bit more about it, here’s another post I made specifically for that.
I Wrote a Blog Post about Using Submodules within Git Repos
While I was in the process of building my website, I wanted to make my site’s primary code open source but keep all my blog post content private. Look at the design, folder structure, colors, and components all you want, but you shouldn’t be able to simply fork my repo, change the picture and name and have access to all the posts I’ve put hours of time and effort into.
So I learned about Submodules, which are one very handy way to have two or more repos work together as a single unit. One project (or more), entirely separate from, yet used within, another project.
This strategy allowed me to have the best of both worlds, but submodules have many other uses too. Have a third-party library you want to use in multiple projects? Git Submodules can help. Have an independent bit of code you’re developing that you want to use in multiple parent projects? Git Submodules can help there too.
This article dives into the whys and hows of Git Submodules. It covers how to create a new submodule, how to add a submodule to an existing repo, update the contents of that submodule within the other repo and download a new project that contains submodules. I also included a section about deploying a repo with a private submodule to Netlify, that was a little tricky for me.