zargony.com

#![desc = "Random thoughts of a software engineer"]

Recursive git: rgit

Here's a little helper that runs a git command on every repository found in subdirs. Put the following ruby code into a file called rgit, make it executable and save it to a bin directory, like /usr/local/bin:

#!/usr/bin/env ruby
if ARGV.empty?
  STDERR.puts "usage: #{File.basename($0)} <cmd> ..."
  STDERR.puts "  Runs git <cmd> in every repository found in subdirs"
  exit
end
dirs = Dir.glob('**/.git').map { |d| d.chomp('/.git') }
dirs.each do |dir|
  puts "-> #{dir}"
  Dir.chdir(dir) do
    system 'git', *ARGV
  end
end

I'm using rgit pull or rgit fetch every morning to retrieve the latest code changes and rgit push every evening to make sure all my changes get pushed to the server. rgit repack -a -d is useful to cleanup all local repositories.

Todo: git submodules should be filtered out. Currently, they are processed like normal repositories, which probably is not what you want.