cfg/bin/git-ps
Knut Ahlers 1352f933fc
Do not remove develop / main branches
- `develop` is the default for git-flow
- `main` the "new default" for git in general

Signed-off-by: Knut Ahlers <knut@ahlers.me>
2022-07-20 16:38:46 +02:00

36 lines
939 B
Bash
Executable file

#!/bin/bash
set -euo pipefail
source "${HOME}/bin/script_framework.sh"
jump_branch="${1:-}"
step "Loading required keys to pull"
git loadkey
step "Fetching data from remote..."
for remote in $(git remote -v | awk '{print $1}' | sort | uniq); do
step "+++ Remote: '${remote}'"
git fetch -p ${remote} --tags
done
[[ -z ${jump_branch} ]] || {
step "Switching to branch ${jump_branch}"
git switch "${jump_branch}"
}
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 ! [[ $branch =~ (develop|main|master) ]]; then
git branch -d ${branch}
fi
done
step "Removing local branches where remote branch is gone..."
if (git branch -vv | grep -q ': gone]'); then
git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D
fi