Created
January 18, 2013 13:50
-
-
Save brujoand/4564658 to your computer and use it in GitHub Desktop.
git repo updater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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