Nicholas DiPiazza
Nicholas DiPiazza

Reputation: 10595

GitHub api - for a forked repository object, how to get what repository its forked from?

GitHub api -

For the getRepos action, you will get a list of the user's repositories.

The repository objects that are returned have some information in them. However, they don't seem to have any information about "what repository am i forked from?"

How can I get that?

Upvotes: 18

Views: 2753

Answers (1)

VonC
VonC

Reputation: 1323953

In the "Get" section of the repo API, you can see two fields which address your question:

The parent and source objects are present when the repo is a fork:

  • parent is the repo this repo was forked from,
  • source is the ultimate source for the network.

When I get my fork of the git repo, I see:

curl -s "https://api.github.com/repos/VonC/git"

  "parent": {
    "id": 36502,
    "name": "git",
    "full_name": "git/git",
    "owner": {
      "login": "git",
      "id": 18133,

You can get the forked repo information by reading the content of the parent field.

Upvotes: 16

Related Questions