Created
July 20, 2018 19:49
-
-
Save valtoni/48c5e8ac2720cadf76e2aec1422d3951 to your computer and use it in GitHub Desktop.
Script to delete branches without remote upstream
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
| #!/bin/sh | |
| while read branch; do | |
| upstream=$(git rev-parse --abbrev-ref $branch@{upstream} 2>/dev/null) | |
| if [[ $? == 0 ]]; then | |
| echo $branch tracks $upstream | |
| else | |
| echo $branch has no upstream configured | |
| git branch -D $branch | |
| if [ -z $? ]; then | |
| echo $branch was successfull deleted | |
| else | |
| echo "$branch was not fully merged. Force it change to -D in script" | |
| fi | |
| fi | |
| done < <(git for-each-ref --format='%(refname:short)' refs/heads/*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment