Skip to content

Instantly share code, notes, and snippets.

@ianmiell
Last active February 14, 2018 19:00
Show Gist options
  • Save ianmiell/921341c5b4cd4da4c670c17119ff4409 to your computer and use it in GitHub Desktop.
Save ianmiell/921341c5b4cd4da4c670c17119ff4409 to your computer and use it in GitHub Desktop.
Get/update all my git repos
#!/bin/bash -eu
set -o pipefail
USERNAME="ianmiell"
GIT_FOLDER="/space/git"
declare -a FAILURES
FAILURES=('')
function finish() {
echo The following repos failed to update:
for failed in "${FAILURES[@]}"
do
echo "$failed"
done
}
trap finish INT EXIT TERM
for page in {1..100}
do
REPOS=$(wget -qO- "https://api.github.com/users/${USERNAME}/repos?per_page=100&page=${page}" | grep full_name | awk '{print $2}' | sed 's/.*\/\(.*\)",/\1/')
pushd ${GIT_FOLDER} > /dev/null 2>&1
for REPO in $REPOS
do
if [ -d "${REPO}" ]
then
(
cd "${REPO}" > /dev/null 2>&1
set +e
git pull
if [[ $? = 1 ]]
then
FAILURES+=("${REPO}")
fi
set -e
)
else
git clone "[email protected]:ianmiell/${REPO}.git"
fi
done
popd
sleep 60 # Wait a minute for API limits
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment