Created
April 7, 2016 00:29
-
-
Save cbednarski/51f92839915cfa8a40f237fa8138dd74 to your computer and use it in GitHub Desktop.
Backup github repos, courtesy @kikitux
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
#!/bin/bash | |
| |
user="`basename ${0%.sh}`" | |
| |
GHTEST="`curl -sS -I https://api.github.com 2>&1`" | |
RET=$? | |
if [ ${RET} -ne 0 ]; then | |
echo "ERR: check internet connection" | |
echo "${GHTEST}" | |
echo "Curl exit code: ${RET}" | |
exit ${RET} | |
fi | |
| |
therepolist="`curl -sSL https://api.github.com/users/${user}/repos | jq -r .[].html_url`" | |
| |
[ -d ${user} ] || mkdir -p ${user} | |
| |
for repourl in ${therepolist}; do | |
repo="${repourl#https://github.com/}" | |
| |
if [ -d ${repo} ] ;then | |
pushd ${repo} | |
#check .git/config for pr/*, add if not present | |
grep 'fetch.*.=.*.+refs/pull/\*/head:refs/remotes/origin/pr/\*' .git/config &>/dev/null | |
if [ $? -ne 0 ]; then | |
git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*' | |
fi | |
git clean -fdx | |
git checkout master | |
git pull -f --prune origin HEAD | |
git fetch --all --tags | |
popd | |
else | |
git clone ${repourl} ${repo} | |
pushd ${repo} | |
git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*' | |
git pull -f --prune origin HEAD | |
git fetch --all --tags | |
popd | |
fi | |
| |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment