Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out which local branches are out of sync with remote

Tags:

git

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).

like image 706
Dallaylaen Avatar asked Apr 18 '12 13:04

Dallaylaen


2 Answers

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
like image 144
Dallaylaen Avatar answered Oct 19 '22 14:10

Dallaylaen


This might help you: git remote show origin I am not sure but it works for me

like image 21
Learath2 Avatar answered Oct 19 '22 12:10

Learath2