Skip to content
code github gh forks cleanup

Delete Old GitHub Forks

By Published 1 min read

Last verified in 2022. APIs or CLI flags may have changed; browse newer #github posts.

I was browsing through my GitHub repositories and realized I have an embarrassing number of forks. A lot of these contain code that is out of date or no longer valid. I used this command to clean up the forks I created before 2021-01-01.

gh search repos \
  --owner jpoehnelt \
  --created="<2021-01-01" \
  --include-forks=only \
  --json url \
  --jq ".[] .url" \
| xargs -I {} \
  gh repo delete {} \
    --confirm

You may need to refresh your auth with the delete_repo scope.

gh auth refresh -h github.com -s delete_repo