18

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?

1 Answer 1

16

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.

6
  • 5
    I wish they would have included that in the repositories provided from the api call "getAuthUser". They include a bunch of stuff no one cares about, but leave out that important stuff. Sep 3, 2013 at 14:54
  • @NicholasDiPiazza I agree: that forces you to make individual queries per repo. But considering the size of parent and source field, GitHub may have excluded them from an API call which lists all repos from a given user.
    – VonC
    Sep 3, 2013 at 14:58
  • Given the list of Repos that came from the getAuthUser call... is there a way to get multiple {parent} {source} elements for more than one repo in a single call? Sep 3, 2013 at 18:51
  • @NicholasDiPiazza from my last comment, I don't think so (not fully tested though)
    – VonC
    Sep 3, 2013 at 18:54
  • 2
    @NicholasDiPiazza so maybe another approach is in order? stackoverflow.com/a/9128958/6309 perhaps? Using developer.github.com/v3/activity/events/types/#forkevent?
    – VonC
    Sep 3, 2013 at 18:57

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.