The 'git submodule' Command

Learn about the "git submodule" command with the help of an example.

We'll cover the following

Git submodules solve these external repository dependency issues with a little overhead. Now that you understand local and remote repositories, it will be much easier to grasp how submodules work.

Tracking copies

Git submodule commands are Git commands used to track copies of other repositories within your repository. The tracking is under your control (so you decide when it gets updated, regardless of how the other repository moves on), and the tracking is done within a file that is stored with your Git repository.

Pay Attention Here!

Git submodules can be very confusing if you don’t follow a few basic patterns or understand how they work. So it’s worth paying attention to this.

Let’s make this more clear with a walkthrough.

You are going to assume you have the alicelib repository created in the previous lesson.

Create Bob’s repository (bob_repo):

1	cd ..
2	mkdir bob_repo
3	cd bob_repo
4	git init
5	echo 'source alicelib' > file1
6	git add file1
7	git commit -am 'sourcing alicelib'
8	echo 'do something with alicelib 9	experimental' >> file1
10	git commit -am 'using alicelib experimental'
11	cat file1

Get hands-on with 1200+ tech skills courses.