DEV Community

Cover image for Using to learn about Git submodules
Kim Hallberg
Kim Hallberg

Posted on

Using to learn about Git submodules

Git submodules have always been mysterious to me, but since I've done some challenges on I figured creating a repository and linking to my challenges from that one would be a great way to learn about them.

What is DevChallenges? 🤔

Devchallenges is designed for everyone who wants to be a software developer, it consists of different projects or you might call it challenges. Each challenge is different and will test you different aspects of coding. It includes small user stories and beautiful designs. It reflects real-life tasks that a developer do daily.

You can also find different paths that will help you navigate your career path. Currently, it has only responsive and front-end path, but I am working on more challenges. You will get a certificate when you complete a path.

How do you make learning fun? 🤘

Learning something new can be challenging at times, so finding a way to make it fun has always seemed to help me.

This time around I wanted to learn about submodules, so linking my challenges to a central repository was a great way to learn, as a bonus, it also gives me a central repository to pass around instead of passing a link to separate challenges.

What is Git submodules? 🙂

The official documentation of submodules describes the issue of wanting to use one project inside another project.

Git addresses this issue using submodules. Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.

To use a submodule you add them as you would a remote repository, but using the submodule command instead of remote.

$ git submodule add
Enter fullscreen mode Exit fullscreen mode

This will create a 404-challenge directory in your repository, alternatively, you can pass in a string overwriting the default directory name.

$ git submodule add 404
Enter fullscreen mode Exit fullscreen mode

You will also notice that git has created a new file called .gitmodules containing configuration about your newly added submodule.

[submodule "404"]
    path = 404
    url =
Enter fullscreen mode Exit fullscreen mode

Updating a submodule 🎉

So you've added a submodule to your repository and you submodule has revived an update that you would like to use, don't fret, just like a regular repository you can fetch updates from a submodule as well.

$ git fetch
Enter fullscreen mode Exit fullscreen mode

Then you can merge the updated changes.

$ git merge origin/master
Enter fullscreen mode Exit fullscreen mode

That might get pretty old, so git has an easier way to fetch an update using the submodule update command.

$ git submodule update --remote
Enter fullscreen mode Exit fullscreen mode

What about deleting a submodule? 😈

Not going to lie, I haven't gotten that far in my learning yet, so I'll ask that you refer to the documentation. 👍

Issues with submodules ⚠️

Working with submodules isn't all rainbows and sunshine though, reading around in the documentation it seems there are issues pertaining to branches in older versions of git.

For instance, switching branches with submodules in them can also be tricky with Git versions older than Git 2.13. If you create a new branch, add a submodule there, and then switch back to a branch without that submodule, you still have the submodule directory as an untracked directory

So do keep that in the back of your mind when working with submodules.

For now, I'm going to keep doing my challenges and reading up more on submodules. 🎉

Do you use submodules? Let me know in the comments. 🤘

Find me on DevChallenges 🔥

You can visit my profile on DevChallenges to see my completed challenges, and if you're a member, I'm open to feedback. 👍

Top comments (1)

stevescruz profile image
Steve Cruz

I liked your hover animation on your Team Challenge Page.