Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2016 01:25
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;
while read repoDir; do
if [ "$repoDir" == "" ]; then
echo "Empty line in gitup.repos found. Skipping..."
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
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
done < ./gitup.repos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment