Skip to content

Instantly share code, notes, and snippets.

@gaarf
Created February 4, 2011 00:45
Show Gist options
  • Save gaarf/810535 to your computer and use it in GitHub Desktop.
Save gaarf/810535 to your computer and use it in GitHub Desktop.
git merge master into all local branches
#!/usr/bin/env ruby
BRANCHES = []
`git branch`.each_line do |line|
branch = line.gsub(/[^\w]/, '')
if line[0]==42
STARTED_ON_BRANCH = branch
end
BRANCHES << branch
end
def backtick(command)
puts "\n--- $ #{command} ".ljust(80,'-')
puts `#{command}`
end
def confirm(prompt)
print "\n***** #{prompt} ? [Y/n] "
gets.strip.downcase != 'n'
end
backtick "git checkout master"
backtick "git pull"
BRANCHES.each do |branch|
unless branch=='master'
backtick "git checkout #{branch}"
if confirm "merge master into #{branch}"
backtick "git merge master"
if confirm "push #{branch} to origin"
backtick "git push"
end
end
end
end
backtick "git checkout #{STARTED_ON_BRANCH}"
puts "all done!\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment