Skip to content

Instantly share code, notes, and snippets.

@kodion
Forked from slavafomin/git-submodules.md
Created July 28, 2018 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kodion/e195b9fafe9e83e9a36a1b8f9c311f2a to your computer and use it in GitHub Desktop.
Save kodion/e195b9fafe9e83e9a36a1b8f9c311f2a to your computer and use it in GitHub Desktop.
Git submodules best practices

Git submodules best practices

Useful commands

— Clone repository with submodules automatically:

git clone --recursive git@github.com:name/repo.git

— Initialize submodules after regular cloning:

git submodule update --init

— Make submodules to track their respective remote branches (instead of being in detached HEAD state):

git submodule foreach -q --recursive 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master)'

— Display status of submodules when git status is invoked:

git config --global status.submoduleSummary true

— Script for pulling the main repo and updating the sumodules automatically:

#!/usr/bin/env bash

git pull "$@" &&
  git submodule sync --recursive &&
  git submodule update --init --recursive

Additional reading

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