1. 安装 GitHub CLI
# macOS
brew install gh
# Windows
winget install GitHub.cli
# Linux
sudo apt install gh
2. 登录 GitHub CLI
gh auth login
示例:
gh auth login
? Where do you use GitHub? GitHub.com
? What is your preferred protocol for Git operations on this host? SSH
? Upload your SSH public key to your GitHub account? C:\Users\<用户名>\.ssh\id_rsa.pub
? Title for your SSH key: <你github上的SSH密钥标题>
? How would you like to authenticate GitHub CLI? Paste an authentication token
Tip: you can generate a Personal Access Token here https://github.com/settings/tokens
The minimum required scopes are 'repo', 'read:org', 'admin:public_key'.
? Paste your authentication token:
这里需要你自己去github上生成一个Personal Access Token, 并粘贴到提示中。需要勾选repo, read:org, admin:public_key这几个scope。
3. 删除所有fork仓库
删除有风险,请谨慎操作。确认是要删除所有fork仓库后, 再执行以下命令。
3.1. 查看所有fork仓库
win11:
查看前10个fork仓库:
gh repo list --fork --limit 10 --json nameWithOwner --jq '.[].nameWithOwner'
如果要查看所有fork仓库, 可以不指定--limit参数。
3.2. 删除所有fork仓库
win11:
删除前10个fork仓库:
gh repo list --fork --limit 10 --json nameWithOwner --jq '.[].nameWithOwner' | % { gh repo delete $_ --yes }
✓ Deleted repository xx/hello01
✓ Deleted repository xx/hello02
✓ Deleted repository xx/hello03
✓ Deleted repository xx/hello04
✓ Deleted repository xx/hello05
✓ Deleted repository xx/hello06
✓ Deleted repository xx/hello07
✓ Deleted repository xx/hello08
✓ Deleted repository xx/hello09
✓ Deleted repository xx/hello10
如果要删除所有fork仓库, 可以不指定--limit参数。
gh repo list --fork --json nameWithOwner --jq '.[].nameWithOwner' | % { gh repo delete $_ --yes }