glqrdw
Last Updated: February 25, 2016
·
323
· jan0sch
2aaae7041aca85da930bcaf14d6768d2

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}"
Say Thanks
Respond
Filed Under