Skip to content

Instantly share code, notes, and snippets.

@adrn
Last active November 2, 2015 17:16
Show Gist options
  • Save adrn/10511f854287ef8a5ef3 to your computer and use it in GitHub Desktop.
Save adrn/10511f854287ef8a5ef3 to your computer and use it in GitHub Desktop.
List all git repositories in a given path, identify which ones have commits waiting to be pushed.

git-report

List all subfolders that are git repositories within a specified path. Displays a check mark next to repositories that are up to date with origin/master. Displays a red x next to repositories with commits waiting to be pushed. Right now just compares local master branch to origin/master.

Install

I put this in ~/bin/, then add this line to my bash profile:

export PATH=$PATH:~/bin/

Usage

From the terminal, call git-report [path].

#!/usr/bin/env python
import os
import subprocess
import sys
try:
arg = sys.argv[1]
except IndexError:
arg = "."
rootdir = os.path.abspath(arg)
for subdir in os.listdir(rootdir):
if os.path.isdir(subdir) and not os.path.basename(subdir).startswith('.'):
# os.chdir(subdir)
proc = subprocess.Popen("git status", shell=True, cwd=os.path.join(rootdir, subdir),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc.wait()
output, err = proc.communicate()
if "Your branch is ahead of" in output:
print("{} \xE2\x9D\x8C".format(subdir))
elif "fatal: Not a git repository" in output:
continue
else:
print("{} \xE2\x9C\x85".format(subdir))
@CarlQLange
Copy link

In case you don't want to break out to python, I do this with a bash script:

gbd () {
        for d in `find . -name ".git"`
        do
                echo -e "\033[0;36m  $d \033[0m"
                git --git-dir=$d --work-tree=$d/.. status -sb
                echo ""
        done
}

@adamwolf
Copy link

adamwolf commented Oct 5, 2015

Nice work. I really like the presentation format. I wrote something like this that also checks other branches, the stash, and a few other things. https://github.com/adamwolf/check_project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment