Git Submodules

Posted on Fri 10 July 2020 in Dev Resources

Cover image
Image by Henry Be

When it comes to understanding git submodules things can get tricky real quick. One of the best resources I have found so far on how to work with them is this video.

You might be wondering what kind of use case does a git submodule apply to. This blog for example has a theme maintained by a 3rd party repo. I don't have any immediate intention to PR any code to that repo and would rather have a way to pull the code into this blog project if need be. What I can do is place that 3rd party code in the themes directory and now I can work with it even though it has it's own git log. All my project cares about what commit it needs to reference in teh submodule. If I want to change the commit my blog points to in the submodule I go into that directory and change the branch.

the main commands from this video are:

git submodule add <url> path_to_submodule
  • git submodule add the command to add a sub module to your project
  • <url> the git repo url
  • path_to_submodule where you want it to exist in your super project