Skip to content

Instantly share code, notes, and snippets.

@katyukha
Created May 27, 2014 10:09
Show Gist options
  • Save katyukha/430e5982c829952bcfa2 to your computer and use it in GitHub Desktop.
Save katyukha/430e5982c829952bcfa2 to your computer and use it in GitHub Desktop.
Execute git command on all git repositories in specified directory
#!/bin/bash
# Update all git directories below current directory or specified directory
# Skips directories that contain a file called .ignore
#
# Params:
# $1 - directory to search repositories in
# all next will be passed to git
#
# Example:
# bash bulk_git.bash ~/projects/ status
HIGHLIGHT="\e[01;34m"
NORMAL='\e[00m'
ROOT_DIR=$1
shift;
COMMAND=$@
function do_git {
local d="$1"
if [ -d "$d" ]; then
if [ -e "$d/.ignore" ]; then
echo -e "\n${HIGHLIGHT}Ignoring $d${NORMAL}"
else
cd $d > /dev/null
if [ -d ".git" ]; then
echo -e "\n${HIGHLIGHT}Working on `pwd`$NORMAL"
git $COMMAND
else
scan *
fi
cd .. > /dev/null
fi
fi
#echo "Exiting update: pwd=`pwd`"
}
function scan {
#echo "`pwd`"
for x in $*; do
do_git "$x"
done
}
cd $ROOT_DIR > /dev/null;
echo -e "${HIGHLIGHT}Scanning ${PWD}${NORMAL}"
scan *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment