Last active
November 29, 2017 18:58
-
-
Save danwdart/3f57bc9ccfbd56a0404bf71db668733d to your computer and use it in GitHub Desktop.
Updates all repos in the current directory
This file contains hidden or 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
#!/bin/bash | |
# All repos in the current directory | |
# uses gitflow http://nvie.com/posts/a-successful-git-branching-model/ | |
for DIR in * | |
do | |
# Directories only | |
[ -d $DIR ] || continue | |
# What is it? | |
echo $DIR | |
# Now, go there | |
cd $DIR | |
# reset & update | |
git fetch --all | |
git push --all origin | |
HAS_UPSTREAM=$(git remote | grep upstream | wc -l) | |
HAS_DEVELOP=$(git branch | grep develop | wc -l) | |
if [ "1" -eq $HAS_DEVELOP ] | |
then | |
BRANCH_MAIN=develop | |
else | |
BRANCH_MAIN=master | |
fi | |
if [ "1" -eq $HAS_UPSTREAM ] | |
then | |
REMOTE_MAIN=upstream | |
else | |
REMOTE_MAIN=origin | |
fi | |
REMOTE_MINE=origin | |
git checkout $BRANCH_MAIN && | |
git branch -u $REMOTE_MAIN/$BRANCH_MAIN && | |
git pull $REMOTE_MAIN $BRANCH_MAIN | |
# now merge develop into all non-merged branches | |
BRANCHES=$(git branch --no-merged | grep -v develop | grep -v master) | |
for BRANCH in $BRANCHES | |
do | |
git checkout $BRANCH | |
git pull --no-edit $REMOTE_MAIN $BRANCH_MAIN || git merge --abort | |
git push -u $REMOTE_MINE $BRANCH | |
# Make sure everything is PR'd | |
hub pull-request -ob$BRANCH_MAIN -m "$BRANCH" | |
notify-send "Branch of $DIR updated" "Branch $BRANCH of $DIR is up to date." | |
done | |
# and reset | |
git checkout $BRANCH_MAIN | |
# now delete all merged branches | |
TODEL=$(git branch --merged | grep -v develop | grep -v master) | |
for BRANCH in $TODEL | |
do | |
git branch -d $BRANCH | |
git push $REMOTE_MINE :$BRANCH | |
notify-send "Branch of $DIR removed" "Merged $BRANCH of $DIR has been removed." | |
done | |
# and clean up | |
git remote prune $REMOTE_MINE | |
# update any dependences locally to the locked versions | |
[ -f src/php/composer.json ] && composer -d=src/php install | |
[ -f composer.json ] && composer install | |
[ -f package.json ] && npm install | |
[ -f bower.json ] && bower install | |
notify-send "Repository $DIR updated" "Repository $DIR has been updated." | |
# ...NEXT! | |
cd .. | |
done | |
notify-send "All repositories updated" "All repositories have been updated." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment