Articles tagged with: tool

Recursive git: rgit

Posted by Andreas on Thursday, October 30, 2008 at 03:24 (CET)

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:

 1 #!/usr/bin/env ruby
 2 if ARGV.empty?
 3   STDERR.puts "usage: #{File.basename($0)} <cmd> ..."
 4   STDERR.puts "  Runs git <cmd> in every repository found in subdirs"
 5   exit
 6 end
 7 dirs = Dir.glob('**/.git').map { |d| d.chomp('/.git') }
 8 dirs.each do |dir|
 9   puts "-> #{dir}"
10   Dir.chdir(dir) do
11     system 'git', *ARGV
12   end
13 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.