Skip to content

Instantly share code, notes, and snippets.

@dehlen
Last active August 8, 2018 06:32
Show Gist options
  • Save dehlen/a44959cf020b239e4ada75ff073be3ff to your computer and use it in GitHub Desktop.
Save dehlen/a44959cf020b239e4ada75ff073be3ff to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
clean_local_and_remote_branches () {
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
}
for repo in `find ~/Development -type d -maxdepth 1`
do
cd $repo
echo "Checking $repo"
if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then
echo "Cleaning $repo"
echo "Stashing changes if necessary"
git stash save --keep-index --include-untracked > /dev/null 2>&1
echo "Checkout develop"
git checkout develop > /dev/null 2>&1
echo "Pulling latest changes"
git pull > /dev/null 2>&1
echo "Removing already merged branches"
clean_local_and_remote_branches > /dev/null 2>&1
echo -e "${BLUE}Done${NC}"
echo $'\n\n'
else
echo -e "${RED}$repo is no git repository. Skipping.${NC}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment