Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# Clone all github.com repositories for a specified user.
if [ $# -eq 0 ]
then
echo "Usage: $0 <user_name> "
exit;
fi
USER=$1
# clone all repositories for user specifed
for repo in `curl -s https://api.github.com/users/$USER/repos?per_page=1000 |grep git_url |awk '{print $2}'| sed 's/"\(.*\)",/\1/'`;do
git clone $repo;
done;
@vke-code

This comment has been minimized.

Copy link
Owner Author

@vke-code vke-code commented Jun 13, 2019

thank you

Wow, I thought this would be a gist that only I use! I am so glad this is useful for someone else!

@RootAndroid58

This comment has been minimized.

Copy link

@RootAndroid58 RootAndroid58 commented Jul 17, 2019

thanks man

@danilofreire

This comment has been minimized.

Copy link

@danilofreire danilofreire commented Aug 22, 2019

Thanks a lot! It's very a very useful little script!

@davidvandenbor

This comment has been minimized.

Copy link

@davidvandenbor davidvandenbor commented May 5, 2021

Hi vke-code! 😄
The script doesn't seem to work in my setup (terminal on Mac OSX)
I can execute the script, but it doesn't seem to return anything.

  1. open terminal
  2. cd to folder where I want to download repo's
  3. type: "sh" and then the path to the sh file, like so:
  4. "sh /path/to/download-all-repos.sh"
  5. after hitting RETURN the terminal responds with:
  6. "Usage: /path/to/download-all-repos/download-all-repos.sh <user_name>"
  7. ??????????

And that's it. Nothing happens after this.

Cheers and thanks in advance,
David!

@vke-code

This comment has been minimized.

Copy link
Owner Author

@vke-code vke-code commented May 6, 2021

@davidvandenbor

Thanks for trying out my gist. You need to additionally specify the username whose repos you'd like to download.

e.g. to download all of your repos:
sh /path/to/download-all-repos.sh davidvandenbor

@davidvandenbor

This comment has been minimized.

Copy link

@davidvandenbor davidvandenbor commented May 6, 2021

Hi vke-code!

IT WORKED!!
Now I know what the problem was, I misunderstood the error message in your sh file and interpreted it as:

type the username inside the bash script (replace <user_name> inside de sh code with github username)

Modification

I modified your sh file to make it a bit more clearer for future users who aren't as familiar with bash scripts. I also modified the error notification that appears if you don't type the Github username:

#!/bin/bash

# This BASH script clones all github.com repositories for a specified user!
# HOW TO USE THE SCRIPT: 
# CD to the directory where you want to download all the repositories (or open terminal there)
# then execute the script by defining the path to where you saved the .sh file, followed by your Github username:
# "sh the/path/to/download-all-repos.sh <github_user_name_here>"
# Then hit RETURN and watch the magic happen

if [ $# -eq 0 ]
  then
    echo "ERROR: Github username is missing, you shoud type THIS in your terminal: "
    echo "$0 <github_user_name_here> "
    exit;
fi

USER=$1

# clone all repositories for specified user:
for repo in `curl -s https://api.github.com/users/$USER/repos?per_page=1000 |grep git_url |awk '{print $2}'| sed 's/"\(.*\)",/\1/'`;do
git clone $repo;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment