Small script for updating all git repositories within a directory.
A simple script that jumps into a given directory (or a default one) and updates all git repos in there. Additionally it checks if an upstream remote exists. If that is the case it fetches the upstream changes.
#!/usr/bin/env zsh
if [[ -z "$1" ]] then
DIR=~/Code
else
DIR="$1"
fi
CURRENT_DIR=`pwd`
cd "${DIR}"
for repo in `ls`; do
cd "$repo"
if [[ -d .git ]] then
echo -e "\033[1mFound git repository in $repo.\033[0m"
git pull
if [[ ! -z `git remote | grep upstream` ]] then
echo -e "\033[1mFetching upstream changes for $repo.\033[0m"
git fetch upstream
fi
fi
cd "${DIR}"
done
cd "${CURRENT_DIR}"
Written by Jens Grassel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#