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"?
2 Answers
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
}
-
2AHA! 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.– mpersicoOct 29, 2019 at 21:01 -
1@mpersico Exactly. Or, as I mention in stackoverflow.com/a/32991784/6309,
git remote get-url origin
.– VonCOct 30, 2019 at 7: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.– mpersicoOct 30, 2019 at 11:56
Yes, do this:
(meta_learning) brandomiranda~/proverbot9001 ❯ git config --get remote.origin.url
git@github.com:brando90/proverbot9001.git
-
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.– mpersicoDec 8, 2022 at 17:13
git config --get remote.origin.url