Skip to content

Instantly share code, notes, and snippets.

@sharnik
Forked from mrsimo/clean_local_branches.rb
Created January 16, 2012 10:34
Show Gist options
  • Save sharnik/1620161 to your computer and use it in GitHub Desktop.
Save sharnik/1620161 to your computer and use it in GitHub Desktop.
branches = `git branch`.chomp.split("\n")
branches.map!(&:strip)
branches.each do |branch|
puts "================================"
puts "Considering: #{branch}"
puts
system "git log --color --stat -n 1 #{branch}"
puts
puts
puts
puts "Want to delete it? (y/n)"
case $stdin.gets.chomp.downcase
when "y"
system "git branch -D #{branch}"
end
puts
puts
puts
end
branches = `git branch -r`.chomp.split("\n")
branches.map!(&:strip)
branches.each do |branch|
puts "================================"
puts "Considering: #{branch}"
puts
system "git log --color --stat -n 1 #{branch}"
puts
puts
puts
puts "Want to delete it? (y/n)"
remote, br = branch.split("/")
case $stdin.gets.chomp.downcase
when "y"
system "git push #{remote} :#{br}"
end
puts
puts
puts
end
system "git prune"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment