Skip to content

Instantly share code, notes, and snippets.

@tuxcanfly
Created November 28, 2016 15:44
Show Gist options
  • Save tuxcanfly/8e3a6fcf902d4af83d06b3587dcf1993 to your computer and use it in GitHub Desktop.
Save tuxcanfly/8e3a6fcf902d4af83d06b3587dcf1993 to your computer and use it in GitHub Desktop.
gitup - update multiple repos while taking care of dirty indexes in different branches
#!/bin/bash
for dir
do
pushd $dir
STASHED=false
BRANCH=false
if [[ -n $(git status --porcelain) ]]
then
git stash
STASHED=true
fi
branch=$(git branch | grep "*" | cut -d ' ' -f 2)
if [ $branch != master ]
then
git checkout master > /dev/null 2>&1
BRANCH=true
fi
git pull --ff-only > /dev/null
if $BRANCH
then
git checkout - > /dev/null 2>&1
fi
if $STASHED
then
git stash pop
fi
git status -s
popd
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment