Submodules are a way to embed other git repositories into your own, retaining a pointer to its origin.
This allows you to grab source changes directly, as well as pushing them back.
- Run
source setup.sh(or.\setup.ps1in PowerShell)
NOTE: If running setup.sh on windows, you can run into problems by sourcing the setup script. Instead, run
./setup.sh, and the folders would be created correctly.
After running the setup script, you'll be left with three repositories inside the exercise folder.
- A
componentrepository cloned fromremote. - A
productrepository. - A
remoterepository. This is the "remote" repository that would exist on your preferred Git repository host, e.g. github.com.
Go to the product repository.
- Add component as a submodule of product by running
git submodule add ../remote include. - What does your working directory look like?
- Does
git statuslook like you expect? - What if you cd to
include? - Run
git diff --cachedinproduct. Where can you find the commit id shown in the+Subproject commit ...line? - Commit the changes on the
productrepository.
Go to the component repository.
- Does it know that it is used as a submodule?
- Make a change to the
componentrepository andgit commitandgit pushit.
Go to the product repository.
- Does
git statusorgit submodule foreach 'git status'tell you anything about this new commit? - Go to the
includedirectory andgit pullthe latest version. - Verify that the change from the
componentrepository is available ininclude. - Go to the
productdirectory. What is the status now in your product repository? Also examine withgit diff. - Go to your
includefolder. Make a change andpushit back to its origin.
Go to the exercise directory. We will make a clone of product to illustrate how submodules in a clone must be initialized.
- Run
git clone product product_alpha. - Go to
product_alphadirectory, how does your working directory look, what does the log say and what is in theincludedirectory? - Run
git submodule init, what does yourincludedir look like? - Run
git submodule update, what does yourincludedir look like now? - Is the latest change from
componentavailable in include?
Go to the product repository.
- Commit the changes on the
productrepository.
Go to the product_alpha repository. We'll ensure that we have the latest changes from product.
- Run
git submodule update. - Is the latest change from
componentavailable ininclude? - Examine the output of
git submodule status. Compare the commit id with thecomponentrepository. - Run
git submodule update --remote. - Is the latest change from
componentavailable in include? - Examine the output of
git submodule status. Compare the commit id with thecomponentrepository.
Draw this entire exercise!