Skip to content

Instantly share code, notes, and snippets.

@knoxilla
Last active October 25, 2021 18:52
Show Gist options
  • Save knoxilla/ff223312cc299dc158cf023de113004a to your computer and use it in GitHub Desktop.
Save knoxilla/ff223312cc299dc158cf023de113004a to your computer and use it in GitHub Desktop.
Git command to get ahead-behind status for current branch against _all_ remotes, not just origin
#!/usr/bin/env bash
# Get ahead-behind status for current branch against _all_ remotes
# To use, put this executable script anywhere on your PATH
# TODO make git alias instead of a PATH git-<command> executable
BRANCH=$(git branch --show-current)
# Could override branch with argument but let's keep it simple
# BRANCH=${1-${BRANCH}}
for remote in $(git remote -v | grep fetch | cut -f 1 -); do
# quietly set remote tracking branch to given remote
git branch -u ${remote}/${BRANCH} 2>&1 > /dev/null
# just the ahead-behind info please
git status | grep 'Your branch is'
# could show more detail, but still ignore untracked files
# git status -uno
# restore remote tracking branch to origin (ASSUMPTION)
git branch -u origin/${BRANCH} >/dev/null
done
# Sample usage and output
# -----------------------
# $ git mstat
# Your branch is up to date with 'upstream/<current-branch>'.
# Your branch is behind 'collaborator/<current-branch>' by 5 commits.
# Your branch is ahead of 'origin/<current-branch' by 2 commits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment