Suppose I have a git repository with several branches. I suspect some of the branches were not pushed upstream, or are outdated, or both (i.e. diverged).
Is there a way to find out which branches are out of sync with remote with one command? (Writing a script is OK but I'd like to know if there's already such a script).
I've done a script. Turns out git branch -v
gives the necessary info.
~/bin/git-total.sh:
#!/bin/sh
for DIR in "$@"; do
# Only git dirs interesting
[ -d "$DIR/.git" ] && cd "$DIR" || continue
# git branch -v gives ahead/behind info
# using perl - sorry for this
MOD=`git branch -v | perl -wlne '/^..(\S+)\s+([a-f0-9]+)\s+(\[ahead\s+(\d+)\])/ or next; print "# Branch ahead: $1"; '`;
# a series of UGLY HACKs to get pretty-printing
[ ! -z "$MOD" ] && MOD="
$MOD"
git status | grep -q '^# Changes' && MOD="$MOD
# Uncommitted changes present"
# print summary
[ ! -z "$MOD" ] && echo -e "$DIR:$MOD"
cd -
done
This might help you: git remote show origin
I am not sure but it works for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With