Git update all repos and branches
mouse 216 · person cloud · link
Last update
2018-07-23
2018
07-23
« — »
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env ruby

Dir['*'].each do |prj|
  next unless File.directory?(prj) && File.exists?("#{prj}/.git")

  Dir.chdir(prj) do
    puts "\n#{'='*10}  #{prj}  ".ljust(70, '=')
    system "git co master"
    system "git fetch --all"

    branches = `git branch`.delete('* ').split("\n")
    branches_maxl = branches.map{|i| i.size }.max
    branches.each do |branch|
      puts "\n#{'~'*10}  #{branch.ljust branches_maxl}  ".ljust(40, '~')
      system "git co #{branch}"
      system "git pull"
    end

    puts "\n#{'-'*10}  (compacting)  ".ljust(40, '-')
    system "git co master"
    system "git gc"
  end
end