|
1 | 1 | # RepoDefender
|
2 |
| -Protect against Repo Takedowns on Github |
| 2 | +Defend against repository takedowns on Github |
| 3 | + |
| 4 | +0) Create multiple accounts on GH |
| 5 | +1) Get https://github.com/cli/cli/blob/trunk/docs/install_linux.md |
| 6 | +2) Authorize your accounts each via |
| 7 | +`gh auth login` |
| 8 | +3) Fork & clone targets |
| 9 | +``` |
| 10 | +#!/bin/bash |
| 11 | + |
| 12 | +# Replace 'user_or_organization' with the actual GitHub username or organization name |
| 13 | +USER_OR_ORG="target-account" |
| 14 | + |
| 15 | +# Replace 'limit' with the number of repositories you want to list. Use a high number to list all. |
| 16 | +LIMIT=100 |
| 17 | + |
| 18 | +# List repositories, fork them, and then clone |
| 19 | +gh repo list $USER_OR_ORG --limit $LIMIT --json nameWithOwner -q ".[].nameWithOwner" | while read repo; do |
| 20 | + # Fork the repository to your account |
| 21 | + echo "Forking $repo..." |
| 22 | + gh repo fork "$repo" --clone=false |
| 23 | + |
| 24 | + # Construct your fork's SSH URL assuming your GitHub username is 'your_username' |
| 25 | + # Replace 'your_username' with your actual GitHub username |
| 26 | + # Note: Replace ':' with '/' in the SSH URL for the correct format |
| 27 | + FORK_SSH_URL="git@github.com:$(echo $repo | sed 's/:/\//')" |
| 28 | + |
| 29 | + echo "Cloning $FORK_SSH_URL..." |
| 30 | + git clone $FORK_SSH_URL |
| 31 | +done |
| 32 | +``` |
| 33 | +4) Out of all your new forked accounts, it makes sense to make some private too |
| 34 | +``` |
| 35 | +#!/bin/bash |
| 36 | + |
| 37 | +# Your GitHub username |
| 38 | +USERNAME="your-account" |
| 39 | + |
| 40 | +# List all repositories for the user, filter for forks, and update to private |
| 41 | +gh repo list $USERNAME --json nameWithOwner,isFork --limit 100 | jq -r '.[] | select(.isFork==true) | .nameWithOwner' | while read repo; do |
| 42 | + echo "Setting $repo to private..." |
| 43 | + gh repo edit "$repo" --visibility private |
| 44 | +done |
| 45 | +``` |
0 commit comments