Add a Submodule
Objective
Include repository B as a submodule in repository A, such that the submodule always points to the latest version of the main
branch of repository B.
Steps
1. Navigate to Repository A
Go to your repository A using the command line:
cd /path/to/your/repo-A
2. Add Repository B as a Submodule
Add repository B as a submodule at a specific location within repository A. Replace URL-of-repo-B
with the URL of your repository B, and path/to/submodule
with the desired directory for the submodule:
git submodule add -b main URL-of-repo-B path/to/submodule
3. Initialize and Update the Submodule
Initialize and update the submodule to clone the latest version of the main
branch:
git submodule update --init --remote
5. Commit the Changes
Save the changes in your repository A:
git add .gitmodules path/to/submodule
git commit -m "Add repo-B submodule and configure to track main branch"
6. Update the Submodule to Get the Latest Changes
To update the submodule to the latest version of the main
branch at any time, use:
git submodule update --remote
Last updated