Skip to content

Instantly share code, notes, and snippets.

@phooky
Created January 5, 2012 05:17
Show Gist options
  • Save phooky/1563831 to your computer and use it in GitHub Desktop.
Save phooky/1563831 to your computer and use it in GitHub Desktop.
A simple wrapper script for git that tracks cloned repositories and implements "git pull-all" to do a git pull in each such repository.
#!/bin/sh
#
# Git wrapper for tracking cloned repositories and implementing
# "pull-all" to update all cloned repositories from their origins.
#
# Add the following to your bashrc to enable:
# alias git=/PATH/TO/git-wrapper.sh
# Todo: parse out options to clone to avoid completely messing up
GIT_MEMO_FILE=~/.git-pulls
GIT_BINARY=/usr/bin/git
if [ "pull-all" = "$1" ]
then
echo "Pulling all cloned repositories."
while read REPO ; do
pushd ${REPO}
${GIT_BINARY} pull
popd
done < ${GIT_MEMO_FILE}
exit 0
fi
${GIT_BINARY} $*
if [ $? = 0 ]
then
EXTRACT_DIR='s/.*\/\([^\.]*\)\.git.*/\1/'
if [ "clone" = "$1" ]
then
if [ -n "${3}" ]
then
memoize_dir="${3}"
else
memoize_dir=`echo ${2} | sed ${EXTRACT_DIR}`
fi
memoize_dir=`pwd`/${memoize_dir}
echo "Tracking clone ${memoize_dir}."
echo ${memoize_dir} >> ${GIT_MEMO_FILE}
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment