Skip to content

Instantly share code, notes, and snippets.

@marinaglancy
Last active March 13, 2019 08:06
Show Gist options
  • Save marinaglancy/e135afabd86b269865500bcd88461f99 to your computer and use it in GitHub Desktop.
Save marinaglancy/e135afabd86b269865500bcd88461f99 to your computer and use it in GitHub Desktop.
Git alias config for checking all submodules
[alias]
is-clean = !git status --ignore-submodules|grep -q 'working tree clean'
is-master = !git status --ignore-submodules|head -1|grep -q 'On branch master'
is-up-to-date-with-master = !git status --ignore-submodules|head -2|tail -1|grep -q 'Your branch is up to date with'
is-behind = !git status --ignore-submodules|head -2|grep -q 'Your branch is behind'
show-header = !bash -c 'echo && echo "--- $0 ---"' $1
status-dirty = !bash -c 'git is-clean && git is-master && git is-up-to-date-with-master || (git show-header $0 && git status --ignore-submodules)' $1
pull-if-behind = !bash -c 'git fetch origin --prune && git is-clean && git is-master && git is-behind && git show-header $0 && git pull' $1
#--------- Fetch origin on all submodules and main branch
f = !git submodule foreach -q 'git fetch origin --prune' && git fetch origin --prune
#--------- Status on all submodules and main branch unless they are on master and up to date
s = !git submodule foreach -q 'git status-dirty "$path"' && git status-dirty CORE
#--------- Pull all submodules and main branch that are on master branch and clean
p = !git submodule foreach -q 'git pull-if-behind "$path" || :' && git pull-if-behind CORE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment