Skip to content

Instantly share code, notes, and snippets.

@AliSajid
Created January 25, 2012 17:10
Show Gist options
  • Save AliSajid/1677357 to your computer and use it in GitHub Desktop.
Save AliSajid/1677357 to your computer and use it in GitHub Desktop.
Git update script
reading remote list...
reading branch list...
./update_repository:41:in `block in get_branches': undefined method `strip' for nil:NilClass (NoMethodError)
from ./update_repository:39:in `each'
from ./update_repository:39:in `get_branches'
from ./update_repository:69:in `<main>'
#!/bin/env ruby
# update.sh
# This script updates all branches to remote hosts.
#~ puts "Reading branch list..."
#~ list = %x( git branch).strip.split(/\n/).each do
#~ |b|
#~ b.gsub!("* ", "")
#~ end
#~ puts "Current branches are: "
#~ list.each do
#~ |b|
#~ puts b.strip
#~ end
#~ puts "Updating github repository"
#~ list.each do
#~ |b|
#~ puts "Now updating #{b.strip} branch."
#~ %x(git push github #{b.strip})
#~ puts "Finished updating #{b.strip} branch."
#~ end
#~ puts "Updating bitbucket repository"
#~ list.each do
#~ |b|
#~ puts "Now updating #{b.strip} branch."
#~ %x(git push bitbucket #{b.strip})
#~ puts "Finished updating #{b.strip} branch."
#~ end
#~ puts "All branches on all repositories have been updated."
#~ puts "Enjoy your git repository"
def get_branches
branches = %x( git branch).split(/\n/).each do
|b|
b.gsub("* ", "").strip
end
branches
end
def get_remotes
remotes = %x( git branch).strip.split(/\n/)
end
def update_repository(remotes, branches)
@remotes, @branches = remotes, branches
@remotes.each do
|remote|
puts "Now updating all branches on #{remote} server."
counter = @branches.count
@branches.each do
|branch|
puts "Now updating #{branch.strip} branch."
%x(git push #{remote} #{branch.strip})
puts "Finished updating #{branch.strip} branch."
end
puts "Finished updating all branches on #{remote} server."
end
end
puts "reading remote list..."
remotes = get_remotes
puts "reading branch list..."
branches = get_branches
puts "Updating repositories..."
update_repository(remotes, branches)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment