You open your laptop. You have a ton of git repos, your own and other people’s.

Before you wade in to make conflicting changes, what state are your repos in? Are you way behind? Maybe you have uncommitted changes…

Here’s a handy scriptlet to get situational awareness on how up to date you are:

  • In good UNIX style, no output means everything is great.
  • Set the environment variable $DEV to where your most important git repos live.

You can find the current version at https://gist.github.com/air/0f0631106161b12f407f

#!/bin/bash

set -o nounset
set -o errexit

[[ ! -z ${DEV} ]] || { echo "DEV is not defined"; exit 1; }

# for each dir in DEV
checkouts=$(find $DEV -maxdepth 1 -type d)
for dir in ${checkouts}; do
  # skip dirs that aren't git clones
  if [[ ! -d ${dir}/.git ]]; then continue; fi

  local_changes=$(git -C ${dir} status --porcelain)
  if [[ ! -z ${local_changes} ]]; then echo -e "${dir}: local changes\n${local_changes}"; fi

  git -C $dir fetch -q
  remote_changes=$(git -C ${dir} log HEAD..origin/master --oneline)
  if [[ ! -z ${remote_changes} ]]; then echo -e "${dir}: remote updates\n${remote_changes}"; fi
done