Created
February 15, 2018 17:38
-
-
Save dbalduini/a7b2c32138ee64347517539bb9b52068 to your computer and use it in GitHub Desktop.
Sync origin with upstream and clean everything locally.
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 | |
git fetch upstream | |
## Remove local branches | |
git remote prune upstream | |
## Clean all gone local branches | |
git fetch -p | |
for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'` | |
do | |
git branch -D $branch | |
done | |
## Remove origin branches that no longer exists on the upstream | |
BRANCH_1="upstream" | |
BRANCH_2="origin" | |
up=$(git branch -r | grep "$BRANCH_1") | |
BRANCHES=$(git branch -r | grep "$BRANCH_2" | sed -e "s/$BRANCH_2\///g" | grep -v "HEAD") | |
for i in $BRANCHES | |
do | |
c=$(echo $up | grep -c "$i") | |
if [ "$c" -lt 1 ]; then | |
echo "PRUNING $i" | |
git push -q origin :$i | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment