Git submodules have always been mysterious to me, but since I've done some challenges on DevChallenges.io 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.
...
- Snippet from Thu Nghiem's post devchallenges.io - 16+ FREE Projects with beautiful designs
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.
- Git Tools - Submodules
To use a submodule you add them as you would a remote repository, but using the submodule
command instead of remote
.
$ git submodule add https://github.com/thinkverse/404-challenge
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 https://github.com/thinkverse/404-challenge 404
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 = https://github.com/thinkverse/404-challenge
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
Then you can merge the updated changes.
$ git merge origin/master
That might get pretty old, so git has an easier way to fetch an update using the submodule update
command.
$ git submodule update --remote
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)
I liked your hover animation on your Team Challenge Page.