‹ jan0sch.de

Small script for updating all git repositories within a directory.

2014-09-03

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}"