Skip to content

Instantly share code, notes, and snippets.

@sixem
Last active March 20, 2022 14:30
Show Gist options
  • Save sixem/757e20d828f3259019ba5c4b23ce1b32 to your computer and use it in GitHub Desktop.
Save sixem/757e20d828f3259019ba5c4b23ce1b32 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Clones the repos of a user and updates them if they already have been cloned.
mkdir -p "$1" && cd "$1"
TOKEN="YOUR_GITHUB_AUTH-TOKEN"
declare -a CLONE=()
declare -a PULL=()
FETCH=$(curl -s -H "Authorization: token $TOKEN" "https://api.github.com/users/$1/repos?per_page=100")
for NAME in $(echo "${FETCH}" | jq -r ".[].name"); do
if [ ! -d "$NAME" ]; then
CLONE=(${CLONE[@]} "$NAME")
else
PULL=(${PULL[@]} "$NAME")
fi
done
for REPO in "${PULL[@]}"; do
echo "$REPO exists - pulling .."
cd "$REPO" && git pull && cd ".."
done
for REPO in "${CLONE[@]}"; do
echo "Cloning $REPO .."
git clone "https://github.com/$1/$REPO.git"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment