Small script for updating all git repositories within a directory.

A simple shell 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`

for repo in "${DIR}/"*; do
  if [[ -d "${repo}/.git" ]] then
    cd "${repo}"
    echo -e "\033[1mFound git repository in $repo.\033[0m"
    git fetch
    if [[ ! -z `git remote | grep upstream` ]] then
      echo -e "\033[1mFetching upstream changes for $repo.\033[0m"
      git fetch upstream
    fi
  fi
done

cd "${CURRENT_DIR}"
Jens Grassel Written by:

Solving problems and burning chrome for fun and profit.