Skip to content

Instantly share code, notes, and snippets.

@sunny
Created February 1, 2018 15:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunny/f751789a61c7e116b1c66ea7ee4bf9fa to your computer and use it in GitHub Desktop.
Save sunny/f751789a61c7e116b1c66ea7ee4bf9fa to your computer and use it in GitHub Desktop.
bin/git-fetch-and-delete
#!/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