gitcheck: check all your git repositories for changes

One of the cool things about distributed version-control systems (VCSs) or source-control managers (SCMs) like bzr or git is that they don’t have to be distributed. Today, I stick virtually any text file I write into a (local) git repository, which means I have quite a number of them. Here’s the bash script I use to check them all for changes.

Since I switched from cvs and svn to bzr and then git, I started to stick nearly every text file I write into a git repo. This means that by now I have on the order of a hundred (local) repositories, and I do not always remember to commit and/or push changes after I made them. Hence, I wrote this small bash script called gitcheck, that I keep in my home directory (actually as .gitcheck so that it doesn’t pollute it) and run for example at the end of a day or week to see what still needs to be committed.


## gitcheck:
##   Check all git repositories in subdirectories, and list the ones with changes
##   30/07/2011, AstroFloyd, bzrcheck
##   18/01/2013, Astrofloyd, gitcheck

# Initialise counters:
let count_all=0
let count_changed=0
let count_unchanged=0

# Set to 1 for more verbose output:
let verbose=0

# Find git repos and loop over them:
for repo in `find . -type d -name ".git"`
    let count_all=${count_all}+1
    # cd to the dir that contains .git/:
    dir=`echo ${repo} | sed -e 's/\/.git/\//'`
    cd ${dir}
    # If there are changes, print some status and branch info of this repo:
    git status -s | grep -v '??' &> /dev/null && {
	echo -e "\n\n \E[1;31m ${dir}\E[0m"
	git branch -vvra
	git status -s | grep -v '??'
	let count_changed=${count_changed}+1
    # If verbose, print info in the case of no changes:
    git status -s | grep -v '??' &> /dev/null || {
	if [ ${verbose} -ne 0 ]; then echo "Nothing to do for ${dir}"; fi
	let count_unchanged=${count_unchanged}+1
    # cd back:
    cd - &> /dev/null

# Report status and exit:
echo -ne "\n\n${count_all} git repositories found: "
echo -ne "${count_changed} have changes, "
echo -ne "${count_unchanged} are unchanged.\n\n"

Syntax highlighted by Code2HTML, v. 0.9.1

This entry was posted in All, Software and tagged , , , , , . Bookmark the permalink.

2 Responses to gitcheck: check all your git repositories for changes

  1. Nice. Do you have your old bzrcheck and gitcheck up in your repo? I’m prob going to automate some of my daily dvcs checks soon (which is how i found your blog post).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s