I needed to do exactly the same. Here is my rubyRuby script.
#!/usr/bin/env ruby
local = []
remote = {}
# preparePrepare
%x[git reset --hard HEAD]
%x[git checkout master] # makesMakes sure that * is on master.
%x[git branch -a].each_line do |line|
line.strip!
if /origin\//.match(line)
remote[line.gsub(/origin\//, '')] = line
else
local << line
end
end
# updateUpdate
remote.each_pair do |loc, rem|
next if local.include?(loc)
%x[git checkout --track -b #{loc} #{rem}]
end
%x[git fetch]