cfg/bin/git-ps

37 lines
882 B
Plaintext
Raw Normal View History

2016-07-21 13:48:49 +00:00
#!/bin/bash
set -o pipefail
set -e
2016-07-21 13:48:49 +00:00
STEP_COLOR="\033[0;36m"
NO_COLOR="\033[0m"
function step {
echo -e ${STEP_COLOR}[$(date +%H:%M:%S)] $1${NO_COLOR}
}
step "Loading required keys to pull"
git loadkey
2016-07-21 13:48:49 +00:00
step "Fetching data from remote..."
for remote in $(git remote -v | awk '{print $1}' | sort | uniq); do
step "+++ Remote: '${remote}'"
git fetch -p ${remote}
done
step "Rebasing branch / updating submodules..."
git pull --rebase && git submodule update --init --recursive
step "Cleaning local branches..."
for branch in $(git branch --merged | grep -v '^*'); do
# Do not delete master as the main branch
if ( test "${branch}" != "master" ); then
git branch -d ${branch}
fi
done
step "Removing local branches where remote branch is gone..."
2016-11-30 11:43:28 +00:00
if ( git branch -vv | grep -q ': gone]' ); then
2016-10-24 06:20:44 +00:00
git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D
fi