Last active
December 11, 2018 08:48
-
-
Save c10b10/fab1646d02b4458f8e28 to your computer and use it in GitHub Desktop.
Clones all the private github repos from a certain organization, including branches, submodules and wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "json"; | |
# Change github credentials and organization name | |
github = {:user => "johndoe", :pass => "password", :org => "twitter"} | |
repos = `curl --user "#{github[:user]}:#{github[:pass]}" https://api.github.com/orgs/#{github[:org]}/repos\?per_page\=200\&type\=private` | |
for repo in JSON.load(repos) | |
puts "\n+++ Starting with " + repo["name"] | |
%x[git clone #{repo["ssh_url"]}] | |
branches = %x[cd #{repo["name"]} && git branch -r] | |
branches = branches.split(/\n/).map{ |branch| branch.split(" ").pop.split("/").pop }.uniq | |
default = branches[0] | |
branches.each{|branch| puts %x[cd #{repo["name"]} && git checkout #{branch} && git submodule update --init --recursive]} | |
# Change to default branch and clone the wiki | |
puts %x[cd #{repo["name"]} && git checkout #{default} && git fetch --all && git pull --all && git clone #{repo["ssh_url"].gsub(".git", ".wiki.git")} wiki] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment