Last active
August 29, 2015 14:07
-
-
Save chreke/b093c576e5bdcb0796cb to your computer and use it in GitHub Desktop.
Ruby script to clean up dead git 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
#!/usr/bin/ruby | |
# Interactively remove branches not in remote, *by name*. This is | |
# useful for pruning branches that were rebased prior to merging, | |
# since those branches will not show up in `git branch --merged`. | |
# List local branches which may have been merged | |
remotes = `git branch -r`.split.map {|x| x.sub('origin/', '') } | |
locals = `git branch`.split.select {|x| x != '*' } | |
complement = locals.select {|x| not (remotes.include? x) } | |
# Ask if local branches should be deleted | |
for branch in complement do | |
puts "'#{branch}' not in remotes, delete?" | |
if gets.chomp == "y" | |
`git branch -D #{branch}` and puts "Deleted #{branch}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment