Skip to content

Instantly share code, notes, and snippets.

@rhaberkorn
Last active January 31, 2019 17:50
Show Gist options
  • Save rhaberkorn/e61cde19d512f2afc23392f003450f59 to your computer and use it in GitHub Desktop.
Save rhaberkorn/e61cde19d512f2afc23392f003450f59 to your computer and use it in GitHub Desktop.
Checkout a Git tag/branch reinitializing all submodules (needs to be registered as an alias)
#!/bin/sh
# This script performs a checkout with same arguments as `git checkout`
# but makes sure that submodules are initialized in exactly the way
# described in the branch/tag.
# This is useful to avoid having to cleanup the tree after checkout
# to prevent files interfering with Eclispe and updating submodules
# manually.
#
# NOTE: This does not prevent other untracked files from intefering
# with Eclipse.
#
# WARNING: THIS WILL DISCARD ALL LOCAL MODIFICATIONS TO YOUR SUBMODULES.
# MAKE SURE TO COMMIT/PUSH OR SAVE THEM BEFORE YOU EXECUTE THIS SCRIPT.
set -e
git submodule foreach 'rm -rf $toplevel/$path'
git checkout "$@"
git submodule sync
git submodule update --init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment