Search code examples
githubgithub-api

How can I batch archive all GitHub repositories in my account?


How do I batch archive my repositories? I'd preferably want to be able to sort through them and figure out a way to not archive my active repositories.

I have hundreds of old GitHub repositories in my account since before the GitHub notifications feature, and now I get vulnerability notifications for all of them. Here's what my notifications look, for projects that were last used maybe 6 years ago:

enter image description here


Solution

  • You can use the GitHub API along with two tools to achieve this. I'll be using:

    • Hub, but you can make direct API calls
    • jq, but you can use any JSON parser

    Here's how:

    1. Fetch a list of all the GitHub repositories in our account, and saving them in a file:

      hub api --paginate users/amingilani/repos | jq -r '.[]."full_name"' > repos_names.txt

    2. Go through that file manually, remove any repositories you don't want to archive

    3. Archive all the repositories in the file:

      cat repos_names.txt | xargs -I {} -n 1 hub api -X PATCH -F archived=true /repos/{}