Created
April 4, 2011 18:44
-
-
Save tbranyen/902154 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/bash | |
| # | |
| # Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com> | |
| # Dual licensed under the MIT and GPL licenses. | |
| # | |
| # github.sh : Automatically clone single or multiple repos into | |
| # a folder, great for setting up a git projects folder. | |
| # | |
| # INSTALL: | |
| # Download to a directory in your path, /usr/local/bin or such; | |
| # you may want to rename to gh for easy access. | |
| # Set executable permissions `chmod +x gh` | |
| # | |
| # CONFIGURATION: | |
| # Set the USERNAME variable below, alternatively: | |
| # git config --global github.user username | |
| # | |
| # USAGE: | |
| # To pull repos from your GitHub | |
| # gh repo1 repo2 repo3 | |
| # | |
| # To pull repos from others GitHub | |
| # gh username/repo1 username/repo2 | |
| # | |
| # To handle multiple repos from a file, create a file named repos.txt | |
| # with repos line by line. Then feed it into this program with: | |
| # cat repos.txt | xargs gh | |
| # | |
| # TODO: | |
| # * Wrap usage in a heredoc to display when no arguments are provided. | |
| # | |
| # vim: ts=2:sw=2:sts=2 | |
| # | |
| # | |
| # Override these with your own values | |
| USERNAME= | |
| # Internal properties | |
| GITHUB_PREFIX=git@github.com: | |
| GITHUB_USERNAME=$(git config --global github.user) | |
| # All arguments | |
| args=$* | |
| # Find each repo and pull from github | |
| for repo in $args; do | |
| # If no username configured, attempt to pull from git --config | |
| if [ -z "$USERNAME" -a -n "$GITHUB_USERNAME" ]; then | |
| USERNAME=$GITHUB_USERNAME | |
| fi | |
| # Test for username | |
| if [ -n "$USERNAME" ]; then | |
| # If a user provides the parameter username/repo pull in that specific repository. | |
| if [ `awk -v repo="$repo" -v delimit="/" 'BEGIN{print index(repo,delimit)}'` -ne 0 ]; 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 | |
| # If no $USERNAME then issue warning | |
| else | |
| echo "Please configure either this script or 'git --config github.user username'" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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