Skip to content

Instantly share code, notes, and snippets.

@velocityzen
Created October 22, 2013 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velocityzen/7097800 to your computer and use it in GitHub Desktop.
Save velocityzen/7097800 to your computer and use it in GitHub Desktop.
git pull in all sub directories. good for refreshing big projects.
#!/bin/bash
current_dir=`pwd`/
dir=$current_dir
usage="Usage : `basename $0` [-d dir] [-h] args\nWhere args are directories that you don't whant to pull"
while getopts hd: opt; do
case $opt in
d)
if [ ! -d $OPTARG ] ; then
echo "$OPTARG is not a directory" >&2
exit 1
fi
dir=$OPTARG
;;
h)
echo -e $usage
exit 0
;;
\?)
echo -e $usage >&2
exit 1
;;
esac
done
shift `expr $OPTIND - 1`
for PARAM;
do
if [ ! -d $dir$PARAM/ ] ; then
echo "$dir$PARAM/ is not a directory" >&2
exit 1
fi
done
for f in `ls $dir`
do
real_f=$dir$f/
if [ -d $real_f ] ; then
count=0
for PARAM;
do
if [ $real_f = $dir$PARAM/ ] ; then
count=1
break
fi
done
if [ $count -eq 0 -a -e $real_f/.git/ ] ; then
cd $real_f
echo -e "\x1B[34mPulling $real_f \x1B[39m"
echo -e "`git pull`\n"
fi
fi
done
cd $current_dir
@adammenges
Copy link

Hey this is pretty nifty, thanks!

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