-
-
Save vke-code/fda27b3ae617e733f3d28e939caee22f to your computer and use it in GitHub Desktop.
#!/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; |
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
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;
?per_page=1000
seems to have been limited to 99 repos only by the github API. Alternatively, we can substitute the query_param with ?page=1
. This is will return 30 repos on a page by page basis. Changing ?page=2
,?page=3
and so on we can get repos beyond the limit of 99.
Here's what I simply did to get the remaining repos beyond 99.
#!/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 specified
for repo in `curl -s https://api.github.com/users/$USER/repos?page=4 |grep git_url |awk '{print $2}'| sed 's/"\(.*\)",/\1/'`;do
git clone $repo;
done;
# clone all repositories for user specified
for repo in `curl -s https://api.github.com/users/$USER/repos?page=5 |grep git_url |awk '{print $2}'| sed 's/"\(.*\)",/\1/'`;do
git clone $repo;
done;
for repo in `curl -s https://api.github.com/users/$USER/repos?page=6 |grep git_url |awk '{print $2}'| sed 's/"\(.*\)",/\1/'`;do
git clone $repo;
done;
Thanks :)
its needs to replace git_url
to clone_url
#!/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 clone_url |awk '{print $2}'| sed 's/"\(.*\)",/\1/'`;do
git clone $repo;
done;
Thanks a lot ! I have added a new functionality.
The added functionality allows for two different actions, depending on the state of the repository.
- Cloning non-existent repositories
- Pulling existing repositories
The code with the changes is here:
https://gist.github.com/ioritz1993/be12fd85fb3fd7a502d01597e8a9bd62
#!/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;
fiUSER=$1
clone all repositories for specified user:
for repo in
curl -s https://api.github.com/users/$USER/repos?per_page=1000 |grep clone_url |awk '{print $2}'| sed 's/"\(.*\)",/\1/'
;do
git clone $repo;
done;
Dam thats awesome thanks
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.
And that's it. Nothing happens after this.
Cheers and thanks in advance,
David!