Last active
April 25, 2022 14:09
-
-
Save AndrewPaglusch/e631629b38613cccf8baab1d5c5a7088 to your computer and use it in GitHub Desktop.
Download All Public GitHub Repos for User
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
| github_username='YourUsernameHere' | |
| github_pat='YourGitHubPATHere' | |
| curl -s -u "${github_username}:${github_pat}" 'https://api.github.com/user/repos?per_page=100' | grep -oP '(?<=clone_url\":[ ]\")[^(\",)]+' | sed "s|https://|https://${github_username}:${github_pat}@|" | while read repo; do | |
| reponame=$(grep -oP '(?<=\/)[^\/]+$' <<< $repo | sed 's/.git//') | |
| if [ -d $reponame ]; then | |
| echo "$reponame exists. Pulling latest changes..." | |
| cd "$reponame" | |
| git reset --hard | |
| git pull --ff-only | |
| cd - | |
| else | |
| echo "Cloning $reponame..." | |
| git clone "$repo" "$reponame" | |
| fi | |
| echo; echo | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment