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/fda63833c48cb46674f8b1a9531c45ec to your computer and use it in GitHub Desktop.
Save andygock/fda63833c48cb46674f8b1a9531c45ec to your computer and use it in GitHub Desktop.
@echo off
rem Create list.txt with each repo name on a new line
rem
rem You can copy all the names from your GitHub repo page with the following command in the browser
rem copy([ ...document.querySelectorAll("a[itemprop]")].map(a=>a.href.match(/.*\/(.*)$/)[1]).join("\n") + "\n")
rem
rem 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
rem copy([...document.querySelectorAll(".js-collaborated-repos a.mr-1")].map(n=>n.innerText.replace(/^.*\//,'')).join("\n"))
rem
rem Then run:
rem github-backup.cmd USERNAME
rem
rem If using FAT32 disk, you may need to temporarily bypass the safe directory check with
rem git config --global --add safe.directory *
rem
rem Remove this later manually with
rem git config --global -unset-all safe.directory
rem
rem Or
rem git config --global --edit
rem
setlocal enabledelayedexpansion
rem Check there is a user argument, the username
if "%~1"=="" goto :help
set username=%1
rem loop through each line of list.txt
for /f "tokens=*" %%f in (list.txt) do call :backup %%f
goto :end
endlocal
rem
rem script ends here
rem
rem subroutine to backup a repo
rem if subdir doesn't exist, git clone repo
rem if exists, enter subdir and git pull
:backup
set repo_name=%1
set repo_url="git@github.com:%username%/%repo_name%"
echo Backing up %repo_name%
if exist %repo_name% (
cd %repo_name%
git pull
cd ..
) else (
git clone %repo_url%
)
goto :eof
rem display help message
:help
echo Usage: github-backup.cmd USERNAME
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment