Created
July 11, 2016 22:46
-
-
Save lonsun/23df675f631f38f942be53bf4fe28570 to your computer and use it in GitHub Desktop.
Fish shell script to remove local Git branches that have been merged and no longer appear on remote.
This file contains 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 git_clean_branches | |
set base_branch develop | |
# work from our base branch | |
git checkout $base_branch | |
# remove local tracking branches where the remote branch is gone | |
git fetch -p | |
# find all local branches that have been merged into the base branch | |
# and delete any without a corresponding remote branch | |
set local | |
for f in (git branch --merged $base_branch | grep -v "\(master\|$base_branch\|\*\)" | awk '/\s*\w*\s*/ {print $1}') | |
set local $local $f | |
end | |
set remote | |
for f in (git branch -r | xargs basename) | |
set remote $remote $f | |
end | |
for f in $local | |
echo $remote | grep --quiet "\s$f\s" | |
if [ $status -gt 0 ] | |
git branch -d $f | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment