Skip to content

Instantly share code, notes, and snippets.

@martin-bb
Created July 12, 2018 18:26
Show Gist options
  • Select an option

  • Save martin-bb/abcc85ecaf147986928c150725f771a5 to your computer and use it in GitHub Desktop.

Select an option

Save martin-bb/abcc85ecaf147986928c150725f771a5 to your computer and use it in GitHub Desktop.
bash function to delete local versions of remotely pruned branches
function gitfp() {
re="\[deleted\].*origin\/(.*)"
# git doesn't go to STDOUT but STDERR...don't know why
output="$(git fetch -p 2>&1)"
if [ -z "$output" ]; then
return 0
fi
echo "${output}"
IFS=$'\n' read -rd '' -a lines <<<"${output}"
for i in "${!lines[@]}"
do
line="${lines[i]}"
if [[ $line =~ $re ]]; then
branch_name="${BASH_REMATCH[1]}"
git branch -D "${branch_name}"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment