Skip to content

Instantly share code, notes, and snippets.

@Jerdak
Created September 23, 2023 03:00
Show Gist options
  • Save Jerdak/e35e2bd1f841d347871ca43759283fc8 to your computer and use it in GitHub Desktop.
Save Jerdak/e35e2bd1f841d347871ca43759283fc8 to your computer and use it in GitHub Desktop.

Revisions

  1. Jerdak created this gist Sep 23, 2023.
    8 changes: 8 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    * Install Homebrew: https://brew.sh/
    * Install Github CLI: https://cli.github.com/

    Linux
    ```bash
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    brew install gh
    ```
    13 changes: 13 additions & 0 deletions backup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # Back up all repositories starting with a certain set of characters.
    #
    # Replace `<GithubAccountName>/...` with the start of the repo(s) you want to remove. e.g. Jerdak/foo_
    gh repo list --json nameWithOwner --jq '.[] | select(.nameWithOwner | startswith("<GithubAccountName>/...")) | .nameWithOwner' |
    while read -r repo; do
    owner=$(echo "$repo" | cut -d '/' -f 1)
    repo_name=$(echo "$repo" | cut -d '/' -f 2)
    gh repo clone "$owner/$repo_name"
    cd "$repo_name"
    tar czf "../${repo_name}.tar.gz" .
    cd ..
    rm -rf "$repo_name"
    done
    11 changes: 11 additions & 0 deletions delete.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # Delete all repositories starting with a certain set of characters
    #
    # Replace `<GithubAccountName>/...` with the start of the repo(s) you want to remove. e.g. Jerdak/foo_
    gh repo list --json nameWithOwner --jq '.[] | select(.nameWithOwner | startswith("Jerdak/difz")) | .nameWithOwner' |
    while read -r repo; do
    owner=$(echo "$repo" | cut -d '/' -f 1)
    repo_name=$(echo "$repo" | cut -d '/' -f 2)
    echo "Deleting: $owner/$repo_name"
    # UNCOMMENT ME TO ACTUALLY DELETE (will require `gh auth refresh -s delete_repo` to have been run at least once)
    #gh repo delete "$owner/$repo_name" --yes
    done