#!/usr/bin/env bash header () { local YELLOW=$(tput setaf 3) local BOLD=$(tput bold) local RESET=$(tput sgr0) printf "\n${YELLOW}${BOLD}== $1 ==${RESET}\n" } log () { local YELLOW=$(tput setaf 3) local BOLD=$(tput bold) local RESET=$(tput sgr0) printf "${YELLOW}-> $1${RESET}\n" } find . | grep -v "init.sh" | xargs rm -rf 1>/dev/null 2>&1 header "CREATING EMPTY REMOTE" mkdir -p remote/super remote/sub-a remote/sub-b cd remote/super && git init --bare && cd ../.. cd remote/sub-a && git init --bare && cd ../.. cd remote/sub-b && git init --bare && cd ../.. header "INITIALIZING SUB-A.." log "Cloning sub-a.." git clone remote/sub-a cd sub-a log "Creating initial commit.." echo "# Sub module A" > README.md git add --all git commit -m "Initial commit." log "Pushing initial commit.." git push -u origin master cd .. header "INITIALIZING SUB-B.." log "Cloning sub-b.." git clone remote/sub-b cd sub-b log "Creating initial commit.." echo "# Sub module B" > README.md git add --all git commit -m "Initial commit." log "Pushing initial commit.." git push -u origin master cd .. header "INITIALIZING SUPER.." log "Cloning super.." git clone remote/super cd super log "Creating initial commit.." echo "# Super" > README.md git add --all git commit -m "Initial commit." log "Adding submodules.." git submodule add ../sub-a git submodule add ../sub-b git commit -m "Submodules added." log "Pushing changes.." git push -u origin master cd .. header "REPO INITIALIZATION FINISHED!" log "Removing local repositories.." rm -rf super sub-a sub-b