Git/Submodules: Difference between revisions
From charlesreid1
| Line 68: | Line 68: | ||
https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules#4438292 | https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules#4438292 | ||
===Checking Out Submodules in Existing Repository=== | |||
If you already have a repository cloned and you just don't have the submodule contents (git won't check out submodule contents by default), you can initialize the contents of the submodules by running: | |||
<pre> | |||
git submodule update --init | |||
</pre> | |||
or, if there are multiple folders, | |||
<pre> | |||
git submodule update --init --recursive | |||
</pre> | |||
===Fetching Changes to Submodules=== | ===Fetching Changes to Submodules=== | ||
Revision as of 06:42, 22 February 2018
Notes
I use submodules to organize groups of related repositories and make checking out lots of repos a breeze.
Adding Submodules to Repository
Check out the repository that you want to put submodules into:
git clone https://charlesreid1.com:3000/rpi/pi-master.git cd pi-master
Now add submodules:
git submodule add <git-repo-url>
Here's the script:
#!/bin/bash git submodule add https://charlesreid1.com:3000/rpi/pi-opencv.git git submodule add https://charlesreid1.com:3000/rpi/pi-startup-services.git git submodule add https://charlesreid1.com:3000/rpi/pi-transmission.git git submodule add https://charlesreid1.com:3000/rpi/pi-stunnel.git git submodule add https://charlesreid1.com:3000/rpi/pi-setup.git git submodule add https://charlesreid1.com:3000/rpi/pi-process-wifi-data.git git submodule add https://charlesreid1.com:3000/rpi/pi-join-wifi.git git submodule add https://charlesreid1.com:3000/rpi/pi-aircrack-batch.git
This will add a .gitmodules file automatically.
When you're done, make the commit:
git commit -am 'adding submodules'
Checking Out Repository with Submodules
Start by checking out the repository with the submodules:
git clone https://charlesreid1.com:3000/rpi/pi-master.git
Initialize the repository submodules:
git submodule init
or, do it all at once:
git clone --recursive https://charlesreid1.com:3000/rpi/pi-master.git
or,
git clone --recurse-submodules https://charlesreid1.com:3000/rpi/pi-master.git
https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules#4438292
Checking Out Submodules in Existing Repository
If you already have a repository cloned and you just don't have the submodule contents (git won't check out submodule contents by default), you can initialize the contents of the submodules by running:
git submodule update --init
or, if there are multiple folders,
git submodule update --init --recursive
Fetching Changes to Submodules
To pull changes for each of the submodules, run
git submodule update --remote
Resources
https://git-scm.com/book/en/v2/Git-Tools-Submodules