submodules

Send to Kindle
home » snippets » git » submodules


Snippets

Ref: http://www.vogella.com/articles/Git/article.html#submodules

# When tracking commits:
git submodule add master URL [path]

# If there are updates to this submodule that have been comitted
# upstream to this superproject, get them this way.
git pull --recurse-submodules  # update the superproject.  gets new SHAs for submodules.
git submodule init  # In case more submodules were added or never init'd
git submodule update --recursive
git submodule status

# Update a submodule and commit the change to the superproject.
cd submodule_directory
# Now get to the SHA you want.  Typically, that might be:
git checkout master
git pull
cd ..  # back to superproject directory
git add submodule_directory  # record the new SHA
git commit -m "submodule updated"
git push


# Another way is to track branches
#
# Providing --branch to git submodule add records the branch it in
# .gitmodules and makes it track that branch.
# Ref: https://github.com/git/git/commit/b928922727d6691a3bdc28160f93f25712c565f6
git submodule add --branch master URL [path]

# Update the submodule to the latest on the tracked branch
git submodule update --remote 
# If you want the HEAD for that branch but not fetch from the remote
# repo for the submodule, use
git submodule update --remote --no-fetch