Search code examples
githubgithub-api

How can I use the GitHub API to find the original repo from a forked repo?


When you're looking at a forked repo in the normal GitHub web interface, it says "Fork of user/repo" and includes a link back to the original (parent) repo that was forked. How can I find that original repo using the GitHub API?

I'm starting from a GitHub user, and I can get a list of that user's repos. I even know which repos are forks, but I can't figure out how to identify the original repo.


Solution

  • https://docs.github.com/en/rest/repos/repos#get-a-repository:

    GET /repos/{owner}/{repo}

    The parent and source objects are present when the repository is a fork. parent is the repository this repository was forked from, source is the ultimate source for the network.