Created
February 1, 2018 15:58
-
-
Save sunny/f751789a61c7e116b1c66ea7ee4bf9fa to your computer and use it in GitHub Desktop.
bin/git-fetch-and-delete
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
#!/usr/bin/env ruby | |
deleted_branches = | |
`git fetch --all --tags --prune --dry-run 2>&1 | grep deleted` | |
.split("\n") | |
.map { |line| line.split('origin/')[1] } | |
.select { |branch| system("git rev-parse --verify #{branch} > /dev/null 2>&1") } | |
deleted_branches.each do |branch| | |
print "Delete #{branch}? Y/n " | |
response = gets.chomp.to_s.downcase | |
puts `git branch -D #{branch}` if ['', 'y'].include?(response) | |
end | |
system 'git fetch --all --tags --prune' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment