1

Let's say there is a repository foo/bar which I forked to me/custom-bar. How do I check programmatically (API call maybe?) given foo/bar that there exists a fork that I own from this upstream? Currently, GitHub has the repos/owner/id/forks API endpoint that returns upto 100 entries if you explicitly mention it. I don't see any parameters for creating a custom query for this particular problem. Counting in the rate-limiting and stuff, I don't think it's possible to know this using this API endpoint if I had say a fork of the linux project where over 20k+ forks exist. Is there any fast and efficient way to know this?

Note: I don't want to use authentication if at all possible.

sangeeth96
  • 1,202
  • 1
  • 11
  • 20

3 Answers3

1

New option (June 2022), directly on GitHub (instead of locally through API)

The repository fork button now displays existing forks

A dropdown has been added to the Fork button to help you quickly find your forks of a repository. This includes forks in your personal account and in organizations that you're a member of.

Example of the "your existing forks" dropdown -- https://i0.wp.com/user-images.githubusercontent.com/771134/175119425-5ca5d020-7acb-4f1a-84bf-272980717f78.png?ssl=1

This feature was inspired by Refined GitHub – an impressive open source project maintained by @fregante.
The feature was requested of GitHub through the GitHub Stars program.

Read more about forking a repository in the GitHub documentation.

We appreciate feedback on this and other topics in GitHub's public feedback discussions.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

As a workaround... you can always try to fork your own repo (POST /repos/:owner/:repo/forks).

As explained in "Is it possible to 'fork a fork' in Github?", that won't be generally possible (for a sigle non-organization account) to do if your own repo is itself a fork.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have two questions about this — 1. Wouldn't it unnecessarily create a new fork if I don't have one? 2. This is not possible w/o authentication which I don't want to do (I'll edit my query) – sangeeth96 Feb 22 '18 at 09:50
  • 1/ yes, you would need to delete it ;) 2/ yes, you need authentication: as I said, it is a *workaround*... – VonC Feb 22 '18 at 09:51
  • Hm... your workaround _works_ but I really want a non-invasive method of doing this. I wish the API allowed passing in some search options. – sangeeth96 Feb 22 '18 at 09:54
  • @SangeethSudheer I understand, and looked for such an API, but did not find one. – VonC Feb 22 '18 at 09:54
  • @SangeethSudheer That being said, https://developer.github.com/v4/ might help crafting a more precise query without the pagination issue. – VonC Feb 22 '18 at 09:55
  • :( Oh, I'll look into that and see if it's possible. Thanks for the suggestions so far. – sangeeth96 Feb 22 '18 at 09:56
0

A solution here will be:

  1. Check your repositories using GET /users/:username/repos
  2. For each repo which fork property is true, GEt repository information using GET /repos/:owner/:repo
  3. Check the parent object in json response (that contains parent folder of fork) and validate if full_name is your foo/bar repo
Juan Rada
  • 3,513
  • 1
  • 26
  • 26