Submodules are a way to embed other git repositories into your own, retaining a pointer to its origin.
This allows you to grab source change directly, as well as pushing them back.
- Run
. 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 . setup.sh or . ./setup.sh, you'll be left with two repositories inside the exercises folder.
- A
productrepository - A
componentrepository.
Go to the product repository.
- Add component as a submodule of product by running
git submodule add ../component/ include. - What does your working directory look like?
- Does
git statuslook like you expect? - What if you cd to
include? - Commit the changes on the
productrepository.
Go to the component repository.
- Does it know that it is a submodule?
- Make a change.
- Commit it on the
componentrepository. - Execute
git checkout master~0to detach the HEAD. This workaround is required in order to push to this repository from thecomponentsubmodule that was checkout inproductrepository.
Go to the product repository.
- Does
git statusorgit submodule foreach 'git status'tell you anything about this new commit? - Go to the
includepath andgit pullthe latest version. - Go to the
productpath. What is the status now in your product repository? - 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. - What happened?
- Go to
product_alphadirectory, how does your working directory look, what does the log say, what is in theincludedirectory? - Use
git submodule init, what does your include dir look like? - Use
git submodule update, what does your include dir look like now?
Go to the product repository.
- Commit the changes on the
productrepository.
Go to the exercise directory. We will make a second clone to illustrate TBD.
- Run
git clone product product_beta. - What happened?
- Go to
product_betadirectory, how does your working directory look, what does the log say?
Draw this entire exercise!