Skip to content

Instantly share code, notes, and snippets.

@andygock
Created July 20, 2022 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andygock/d8a490ae233909735edcea478b74cddc to your computer and use it in GitHub Desktop.
Save andygock/d8a490ae233909735edcea478b74cddc to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Create list.txt with each repo name on a new line
#
# You can copy all the names from your GitHub repo page with the following command in the browser
# copy([ ...document.querySelectorAll("a[itemprop]")].map(a=>a.href.match(/.*\/(.*)$/)[1]).join("\n") + "\n")
#
# Or open settings, repositories, and copy the names from the list, this method below includes repos which you collaborate with, so you may need to just manually remove them
# copy([...document.querySelectorAll(".js-collaborated-repos a.mr-1")].map(n=>n.innerText.replace(/^.*\//,'')).join("\n"))
# Then run:
# bash github-backup.sh USERNAME
#
# Tip, if using PuTTY, you can convert key to OpenSSH format, then first use:
# eval `ssh-agent`
# ssh-add /path/to/key
#
# When using WSL, it may help to configure /etc/wsl.conf
# [automount]
# options = "metadata"
#
USERNAME=$1
if [[ $USERNAME = "" ]]; then
echo "Usage: backup.sh USERNAME"
exit 1
fi
while IFS= read -r repo
do
repo_url="git@github.com:${USERNAME}/${repo}"
if [ -d "$repo" ]; then
echo "Updating ${repo}"
cd "$repo"
git pull
cd ..
else
echo "Cloning ${repo}"
git clone "$repo_url"
fi
done < list.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment