Created
March 17, 2011 17:14
-
-
Save vraravam/874724 to your computer and use it in GitHub Desktop.
kill local committed branches in git
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 | |
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