Skip to content

Instantly share code, notes, and snippets.

@elasticdog
Last active May 9, 2019 18:19
Show Gist options
  • Save elasticdog/8806073 to your computer and use it in GitHub Desktop.
Save elasticdog/8806073 to your computer and use it in GitHub Desktop.
Working with Git Submodules

Add New Submodule

$ cd ~/.dotfiles/
$ git submodule add http://github.com/scrooloose/nerdtree.git vim/bundle/nerdtree
$ git submodule init
$ git commit -m 'Add nerd tree plugin as submodule'

Updating

Git submodules are locked to specific commits in their respective repositories...in other words, updating the parent repo will not do the same for that project's submodules.

Running git submodule update only makes sure that the submodules are at the specified cached revision, not the upstream latest. To actually update all of your submodules to the latest upstream HEAD revisions:

$ cd ~/.dotfiles/
$ git submodule foreach git fetch
$ git sumbodule foreach git merge origin/master
$ git commit -a -m 'Update all submodules to latest upstream HEAD revision'
$ git push

Remote Machine

$ cd ~/.dotfiles/
$ git pull
$ git submodule update

Status Info

$ git submodule status
$ git ls-files --stage

Remove

To remove a submodule from your repository, you must edit the obvious .git/config and .gitmodules files, but also run this command to finish the job:

$ git rm --cached path/to/submodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment