#!/bin/sh REPOS="repository_argument_required" if [ "${1}X" = "X" ]; then echo "ERROR: repository argument required" exit 1 else REPOS="${1}" fi DEST_DIR=`basename ${REPOS} .git` if [ -d ${DEST_DIR} ]; then echo "ERROR: ${DEST_DIR} already exists; not cloning" exit 1 fi # Clone an entire repository, including all the branches. git clone ${REPOS} # Get all the branches and set up remote tracking as needed. SAVED_CWD=`pwd` SAVED_IFS=${IFS} IFS=' ' cd ${DEST_DIR} for remote in `git branch -r`; do if echo "${remote}" | grep -q " -> "; then echo "Skipping '${remote}' from ${REPOS}" else echo "Doing '${remote}' from ${REPOS}..." ### TODO: This doesn't work because when we set IFS to \n ### (to avoid the "foo -> bar" problem) now the $remote might have ### spaces in it. Pondering. git branch --track "${remote}" `basename "${remote}"` echo "Done." fi done # There shouldn't be any changes, so we could use fetch, but let's use # pull just to check. git pull --all cd ${SAVED_CWD} IFS=${SAVED_IFS}