Skip to content

Instantly share code, notes, and snippets.

@tbranyen
Created April 4, 2011 18:44
Show Gist options
  • Select an option

  • Save tbranyen/902154 to your computer and use it in GitHub Desktop.

Select an option

Save tbranyen/902154 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
# Dual licensed under the MIT and GPL licenses.
#
# github.sh : Automatically clone multiple repos into a folder,
# great for setting up a git projects folder.
#
# Configuration:
# Configure the USERNAME variable. chmod +x github.sh.
#
# Usage:
# To pull repos from your GitHub
# ./github repo1 repo2 repo3
#
# To pull repos from others GitHub
# ./github username/repo1 username/repo2
#
# TODO:
# * Error checking and fallbacks
# * Automatically pull github username from GIT
#
# vim: ts=2:sw=2:sts=2
#
#
# Override these with your own values
USERNAME=
GITHUB_PREFIX=git@github.com:
# All arguments
args=$*
# Find each repo and pull from github
for repo in $args; do
#
GITUSERNAME= `git config --global github.user`
if [ !$USERNAME -a $GITUSERNAME ]; then
$USERNAME=$GITUSERNAME
fi
# If a user provides the parameter username/repo pull in that specific repository.
if [ `awk -v a="$repo" -v b="/" 'BEGIN{print index(a,b)}'` ]; then
echo "Pulling in $repo";
git clone $GITHUB_PREFIX$repo.git
# Use the default user specified.
else
echo "Pulling in $USERNAME/$repo";
git clone $GITHUB_PREFIX$USERNAME/$repo.git
fi
done
@hosamshahin
Copy link

I made some changes to you script to make it clone multiple repository. All I needed is to clone the latest commit for each repo. You can find the modified script at https://gist.github.com/hosamshahin/99d4642c9762a68d10d4afb462e89575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment