How to Clone All Repositories from a GitHub Account

Use a Bash Script!

If you're like me and use a lot of different devices (and sometimes decide to just wipe your device and start with a new OS), you probably know the pain of cloning all your old code repositories down to your local file system.

If you're using GitHub, you can easily clone all of your code back down in just seconds. First, create a bash script - I do so by opening a new file in gedit, but you can use nano, vim, or something else:

gedit clone_github_repos.sh

Next, paste in the following information. Note that you can replace the word users in the first line with orgs and type an organization's name instead of a user's name.

CNTX={users}; NAME={YOUR-USERNAME}; PAGE=1
curl "https://api.github.com/$CNTX/$NAME/repos?page=$PAGE&per_page=100" |
  grep -e 'git_url*' |
  cut -d \" -f 4 |
  xargs -L1 git clone

Finally, save the bash script and make it executable.

chmod a+x clone_github_repos.sh

Now you can run the script and should see the cloning process begin.

./clone_github_repos.sh

Leave a Comment

Comments are saved as Markdown and cannot be edited or deleted.

Comments

2021-04-21 02:41:22

Christian Cleberg

FYI - There are similar API solutions available for GitLab and Sourcehut.