#!/bin/bash BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') echo "Update changes" git fetch -u origin $BRANCH:$BRANCH git pull --ff-only origin $BRANCH:$BRANCH echo "Changing branch to $BRANCH" git checkout $BRANCH echo "Prunning local branches that were removed in remote..." git remote update --prune git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done echo "Git GCing" git gc git prune echo "Done" echo "Listing remaining branches:" git branch --list