Creating a duplicate GitHub org (script)

I had an existing GitHub organization. It had working code on it, but I needed to duplicate the repos on a separate organization, not through forking off or any connection to the first organization.

bash it is…

 

#! /bin/bash

# arg is list file
# directory to work in
DIR="/Users/dsm/construct"
# GitHub server address
GITS="gitserver"

# cat a list of repos
for i in `cat $1`
do
    rm -rf $DIR/$i
    # for each repo
    git clone git@${GITS}:NebulaGM/$i
    cd $i
    git pull --all
    # add remote
    git remote add nebula git@${GITS}:Nebula/$i
    # push rc to remote
    if [[ `git checkout rc` ]];  then
        git push nebula --all
    fi
    if [[ `git checkout production` ]]; then
        git push nebula --all
    fi
    if [[ `git checkout master` ]]; then
        git push nebula --all
    fi
    cd $DIR
    rm -rf $DIR/$i
done

 

Thus Nebula org gets the base branches from the gold master (NebulaGM) org. This new org will be worked with to add licensing and remove any proprietary cruft before completing pushing this work out as an Open Source project.

$1 is a file containing one repo name on each line. When I set up Nebula org I automated setting up the repos with duplicate names, so org to org they are identical. And while we working the code in parallel (one gets open-sourced and the other remains internal and proprietary), this can be used to sync them going forward.

— doug