
A forking mess
if you are an active github user u maybe how it feels to have a lot of github forks. I mean dont get me wrong the github fork feature is amazing, but if u are not competent with it,it may lead to huge forking project mess.
One way to delete the repositorie is to delete it manually so you can go to settings

And then scroll to the danger zone

press “Delete this repository”

then press the “I want to delete this repository”

lastly you must to confirm to delete the repository by retyping the username and the repository name
ITS TOO MUCH HASSLEEE!!
look if you wanna delete one or two repositories its finee i guess. But if you wanna delete a lot of repositories its too much hassle
Using Github APIs
one way to effeciently doing it as always is to use the github API. according to GPTs Github API is “The GitHub API (Application Programming Interface) is a set of rules and tools that allows developers to interact with the GitHub platform programmatically. It provides a way for developers to automate various tasks related to managing repositories, issues, pull requests, user profiles, and more on GitHub.” well that summerize is well
Using PyGithub to Use Github APIs
PyGithub
is a Python library that provides a convenient and user-friendly way to interact with the GitHub API. It serves as a wrapper around the GitHub API, making it easier for developers to perform various GitHub-related operations directly from their Python scripts or applications.
lets goo, first u need to install the PyGithub
by
pip install PyGithub
and then open your Visual Studio Code, or just notepad or even just python terminal lol
import the Github API
from github import Github
Set your GitHub username and access token
my_username = “your_username_goes_here”
access_token = “your_access_token_goes_here”
Create a Github instance using PyGithub
g = Github(access_token)
Retrieve your repositories
my_repos = g.get_user(my_username).get_repos()
Extract the name and fork status of each repository
repo_info = [{“name”: repo.name, “fork”: repo.fork} for repo in my_repos]
Filter to return only the repositories which are forked
forked_repos = [repo for repo in repo_info if repo[“fork”]]
The next step involves manually, and very carefully selecting the repositories you want to delete.
If you want to delete all forked repositories (!), simply set
to_delete = [repo[“name”] for repo in forked_repos]
Otherwise, create a list of repositories to delete
to_delete = [“bob-does-tidytuesday”, “melindas-cool-project”, “a-random-r-package”]
Finally, we delete using the PyGithub library
for repo_name in to_delete:
repo = g.get_repo(f”{my_username}/{repo_name}”)
repo.delete()
print(f”Repository ‘{repo_name}’ has been deleted successfully.”)
And thennn done lol
Deleting mass repositories like this is an efficient way to do. But you must remember unlike the manual deleting if you use the API there is no some confirmation about the deletion so be careful!. Hope this tutorial helps :)