Created
January 4, 2017 21:18
-
-
Save tijn/ed0d36248340b5719fa7accb52be4a31 to your computer and use it in GitHub Desktop.
remove merged branches; could be generalized and cleaned up but it's already useful in its current form
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
#!/usr/bin/env ruby | |
if ARGV.include? '--help' | |
puts "git-scrub" | |
puts | |
puts "Remove all merged and stale branches." | |
puts | |
puts " merged = merged into master (the command will only run on the master branch)" | |
puts " stale = removed from the remote" | |
exit 0 | |
end | |
current_branch = `git rev-parse --abbrev-ref HEAD`.strip | |
if current_branch != 'master' | |
STDERR.puts 'not on master branch' | |
exit 1 | |
end | |
merged = `git branch --merged | grep -v 'master'`.split | |
merged.each do |branch| | |
STDERR.puts branch | |
`git branch -d "#{branch}"` | |
end | |
`git remote prune origin` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment