Last active
August 29, 2015 14:04
-
-
Save mshuler/0cddeec5bb7f46dadbec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Update all the git repositories under a directory. | |
# | |
################ | |
# ToDo: handle multiple remotes? | |
################ | |
# | |
# If script is placed in your $PATH, then hardcode REPODIR, | |
# or just drop it in the desired REPODIR (good for updating a specific REPODIR). | |
# | |
#REPODIR=~/git/ | |
REPODIR="$( dirname $0 )" | |
if [ ! -d $REPODIR ]; then | |
echo "$REPODIR not found.." | |
exit 1 | |
fi | |
################ | |
# | |
# Find all the git repositories under REPODIR. | |
# | |
REPOSITORIES=$( find ${REPODIR} -maxdepth 1 -mindepth 1 -exec test -d {}/.git \; -print -prune | sort ) | |
if [ -z "${REPOSITORIES}" ]; then | |
echo "No git repositories found in ${REPODIR}.." | |
exit 1 | |
fi | |
################ | |
################ | |
co_pull () { | |
# check out each locally tracked branch and pull | |
for branch in $( git for-each-ref --format='%(refname:short)' refs/heads/ ); do | |
git checkout ${branch} | |
git pull | |
git fetch --tags | |
done | |
# prune branches that were deleted from the remote | |
git remote prune origin | |
# set CLEAN="true" in env to git clean | |
if [ "${CLEAN}" = "true" ]; then | |
git clean -xdf | |
fi | |
} | |
for repo in ${REPOSITORIES}; do | |
( | |
cd ${repo} | |
echo "=== Updating ${repo} ===" | |
co_pull | |
) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment