How to detect a repo is a forked repo?

I want to detect a git repo is a forked repo to auto add upstream remote

@HomyeeKing depends what you mean by ‘detect’.
But If you want query details of whether a repository is a fork and its forking network the GRaphQL V4 API for repositories has information available on isFork, parent if the repository is a fork, forkingCount of many forks there are of this repository in the whole network, a list of direct forked repositories.

https://docs.github.com/en/graphql/reference/objects#repository

There is also more limited information through the REST V3 API
https://docs.github.com/en/rest/reference/repos#get-a-repository

1 Like