6

More specifically, how do I tell if the origin of the repo on disk is a fork of some repo? I am thinking that it should be some API call, but I am not sure. Can I rely on "remote.upstream.url"?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
mpersico
  • 766
  • 7
  • 19

2 Answers2

4

You could use the GitHub API for Repositories to get a specific repo

GET /repos/:owner/:repo

(you can use a curl call from command line)

The JSON answer will include a "fork" field: value true or false.


Another approach, using the GitHub CLI gh repo view command:

gh repo view VonC/git-cred --json isFork
{
  "isFork": false
}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    AHA! I can ask MY repo what is it is a fork of. So :owner/:repo comes from `git config --get remote.origin.url`, looking for `"fork": true` and `"full_name:"` in `"parent"`. Thank you. – mpersico Oct 29 '19 at 21:01
  • 1
    @mpersico Exactly. Or, as I mention in https://stackoverflow.com/a/32991784/6309, `git remote get-url origin`. – VonC Oct 30 '19 at 07:20
  • AHA2! I’ll be updating with this gem today. I try to read the release notes every time my machine gets a new git package but sometimes I miss it. – mpersico Oct 30 '19 at 11:56
-3

Yes, do this:

(meta_learning) brandomiranda~/proverbot9001 ❯ git config --get remote.origin.url
git@github.com:brando90/proverbot9001.git
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
  • 1
    This will tell me if the local repo is a clone. It does not tell me if the remote.origin.url is itself a fork. – mpersico Dec 08 '22 at 17:13