Skip to content

Instantly share code, notes, and snippets.

@vraravam
Created March 17, 2011 17:14
Show Gist options
  • Save vraravam/874724 to your computer and use it in GitHub Desktop.
Save vraravam/874724 to your computer and use it in GitHub Desktop.
kill local committed branches in git
#!/usr/bin/env ruby
require 'open3'
def system_puts(command)
puts command
system command
end
branches = `git branch`.split("\n")
current_branch = branches.select{|l| l =~ /^\*/}.first.gsub("\* ", "")
raise "Should not run this when not in master" unless current_branch == 'master'
(branches - ["* master"]).each do |branch|
system_puts("git checkout #{branch}")
system_puts("git pull")
Open3.popen3("git status") do |i,o,e|
if o.readlines.include?("nothing to commit (working directory clean)\n")
system_puts("git checkout master")
system_puts("git branch -d #{branch}")
else
system_puts("git checkout master")
puts("****** #{branch} could not be deleted due to uncommitted changes")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment