Skip to content

Instantly share code, notes, and snippets.

@nas
Created July 3, 2010 05:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nas/462335 to your computer and use it in GitHub Desktop.
Save nas/462335 to your computer and use it in GitHub Desktop.
Automate git pulling
#!/usr/local/bin/ruby -swI .
#
# AUTOMATE UPDATING ALL PROJECTS
#
# Problem: going to each project and then pulling changes.
# Solution: Automate git pulling for all my projects
#
# 1. Create a pull_projects file and add the code from this gist
# 2. Move the file into a directory that is in your path, i.e. $PATH
# 3. Make the file executable, eg. chmod +x /usr/local/bin/pull_projects
# 4. Run e.g. pull_projects dir1_with_projects dir2_with_projects
# 5. Optional: run this on terminal startup so you dont even have to do it manually
if ARGV.length == 0
raise "You must specify atleast one project directory to pull changes from remote repository"
end
ARGV.each do |projects_dir|
puts "Starting to pull projects in #{projects_dir}\n"
dirs = Dir.entries projects_dir
dirs.reject!{|entry| entry.match(/^\./)}
dirs.each do |entry|
full_dir_path = "#{projects_dir}/#{entry}"
if File.directory? full_dir_path
Dir.chdir(full_dir_path)
check_diff = `git diff`
# Don't pull if I have local changes
unless check_diff.match(/^$/)
puts "You have pending changes in #{entry}"
else
puts "PULLING #{entry}....\n"
system "git pull"
end
Dir.chdir('../')
end
end
end
@rarajabs
Copy link

Hi, do your code support for ssh access?

@nas
Copy link
Author

nas commented Feb 22, 2012

yes it does if you have you ssh keys in the right places,

@rarajabs
Copy link

nice :). thank you.

but I am using windows platform, maybe need to test run on my windows first.

anyway, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment