Created
July 12, 2018 18:26
-
-
Save martin-bb/abcc85ecaf147986928c150725f771a5 to your computer and use it in GitHub Desktop.
bash function to delete local versions of remotely pruned branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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