Skip to content

Instantly share code, notes, and snippets.

@df-a
Created May 8, 2023 02:43
Show Gist options
  • Save df-a/a4f441f9c6892a2b935baf09ff15324c to your computer and use it in GitHub Desktop.
Save df-a/a4f441f9c6892a2b935baf09ff15324c to your computer and use it in GitHub Desktop.
Git submodule commands

To fetch Git modules, you can use the following command:

git submodule update --init --recursive

This command will initialize and update any submodules defined in the Git repository. It will clone the submodules if they have not already been cloned, or update them to the latest commit if they have already been cloned.

If the repository has nested submodules, you may need to use the --recursive option to ensure that all submodules are updated.

You can also use the git submodule foreach command to execute Git commands on each submodule. For example, to pull the latest changes for all submodules, you can use the following command:

git submodule foreach git pull origin master

This will execute the git pull origin master command on each submodule, pulling the latest changes from the master branch of the remote repository.

@df-a
Copy link
Author

df-a commented May 8, 2023

Loop to initialize multiple efficiently

(Added "-f" to force creation of subfolders)

submodules=(
    "https://github.com/dimsemenov/Magnific-Popup.git"
    "https://github.com/dinbror/blazy.git"
    "https://github.com/gdsmith/jquery.easing.git"
    "https://github.com/recurser/jquery-simple-color.git"
    "https://github.com/df-a/novacancy.js.git"
    "https://git@github.com/kenwheeler/slick.git"
    "https://github.com/bgrins/spectrum.git"
    "git@github.com:df-a/languageicons.git"
)

for submodule in "${submodules[@]}"
do
    git submodule add -f "$submodule" "web/libraries/$(basename "$submodule" .git)"
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment