Skip to content

Instantly share code, notes, and snippets.

@josephoaks
Created December 16, 2016 21:34
Show Gist options
  • Save josephoaks/8331372b15f059250569dc5560d83329 to your computer and use it in GitHub Desktop.
Save josephoaks/8331372b15f059250569dc5560d83329 to your computer and use it in GitHub Desktop.
#!/bin/sh
sep='##########'
localpath=`pwd`
for x in */; do
x=`echo $x | sed s#/##` #Get repo name from base directory structure
header="$(tput setaf 1)$sep Processing $x $d$sep$(tput sgr0)" #Set header for printing repo info
head=`git -C $localpath/$x rev-parse --abbrev-ref HEAD` #Set head name
hash=`git -C $localpath/$x rev-parse HEAD` #Set head hash
echo $header #Print header
cd $localpath/$x #Change directory to working repo
remote=`git ls-remote upstream -h $head \
$(git rev-parse --abbrev-ref @{u}|sed 's/\// /g') | cut -f1` #Set upstream hash for comparison
git -C $localpath/$x checkout $head #Ensure your on the HEAD
if [ $hash == $remote ]; #Compare local hash to upstream hash
then
echo "$(tput setaf 2)Everything is up to date$(tput sgr0)" #Print if nothing needs to update
else #else pull updates and update remote
git -C $localpath/$x pull upstream $head
git -C $localpath/$x push origin $head
fi
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment