Skip to content

Instantly share code, notes, and snippets.

@MikeCraig418
Last active April 23, 2020 17:51
Show Gist options
  • Save MikeCraig418/9065fbf03bf128170ded539cfa93f221 to your computer and use it in GitHub Desktop.
Save MikeCraig418/9065fbf03bf128170ded539cfa93f221 to your computer and use it in GitHub Desktop.
Working with Git Submodules

https://www.vogella.com/tutorials/GitSubmodules/article.html

Cloning a repository that contains submodules

git clone https://github.com/bytelaunch/xxx.git --recursive

If you already have cloned a repository and now want to load it’s submodules you have to use submodule update.

git submodule update --init
# if there are nested submodules:
git submodule update --init --recursive

Pulling with Submodules

# pull all changes in the repo including changes in the submodules
git pull --recurse-submodules

# pull all changes for the submodules

# update your submodule --remote fetches new commits in the submodules
# and updates the working tree to the commit described by the branch
git submodule update --remote

git submodule update --recursive

Executing a command on every submodule

git submodule foreach 'git reset --hard'
# including nested submodules
git submodule foreach --recursive 'git reset --hard'

Adding a submodule to repo

git submodule add https://github.com/bytelaunch/nova-last-login.git packages/bytelaunch/nova-last-login

Workflow Tips

  • Enter into a submodule's directory
  • Make any changes, and push with git push
  • After the submodule/subrepo has been pushed, run 'git add .' and 'git commit' on main repo, this will sync the latest pushed submodule to the remote project

Example:

git submodule foreach 'git add .; git commit -m "Removed dump"; git push;'
git status # See changes
git add . # Add relevant changes
git commit -m "Updated submodules"
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment