Skip to content

Instantly share code, notes, and snippets.

@rbeer
Created April 28, 2016 01:25
Embed
What would you like to do?
simple repo updater
#! /bin/env bash
# `gitup.repos` is a text file
# with one absolute path per line
if [ ! -e ./gitup.repos ]; then
echo "No repo list (gitup.repos) found!"
exit 1;
fi
while read repoDir; do
if [ "$repoDir" == "" ]; then
echo "Empty line in gitup.repos found. Skipping..."
continue
fi
echo "Entering $repoDir"
cd "$repoDir"
# making sure branch is master
git checkout master
if [ $? -ne 0 ]; then
echo "Dirty working directory! Stashing..."
BRANCH=$(git stash | line | sed -rn 's/Saved working directory and index state WIP on (.*): .*/\1/p')
git checkout master
fi
echo "Pulling from 'origin' remote..."
git pull origin master
if [ "$BRANCH" != "" ]; then
echo "Returning to branch: $BRANCH"
git checkout $BRANCH
echo "Popping stash..."
git stash pop
fi
done < ./gitup.repos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment