Skip to content

Instantly share code, notes, and snippets.

@brujoand
Created January 18, 2013 13:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brujoand/4564658 to your computer and use it in GitHub Desktop.
Save brujoand/4564658 to your computer and use it in GitHub Desktop.
git repo updater
function gitupdate(){
repo=~/src
old_wd=`pwd`
gitroots=`for path in $repo/*/.git; do echo $path; done | sed 's/\/\.git//g'`
for gitroot in $gitroots; do
echo -e "\033[1;30m\nUpdating $gitroot:\033[0m"
cd $gitroot
branch=`git branch | sed -n 's/^\* //p'`
if [ -z "`git status --porcelain`" ]; then
echo -e "\033[1;30mBranch is clean, rebasing master\033[0m"
git checkout master -q
git pull --rebase > /dev/null
git checkout $branch -q
else
echo -e "\033[1;31mBranch is dirty, stashing\033[0m"
git stash -q
git checkout master -q
echo -e "\033[1;30mRebasing master\033[0m"
git pull --rebase > /dev/null
git checkout $branch -q
echo -e "\033[1;31mApplying stash\033[0m"
git stash apply -q
fi
done
cd $old_wd > /dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment