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"?
Is there a way to determine if my local clone is a fork of some github repo?
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
}
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. –
Briefs @Briefs Exactly. Or, as I mention in https://mcmap.net/q/36062/-how-to-determine-the-url-that-a-local-git-repository-was-originally-cloned-from,
git remote get-url origin
. –
Reaper 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. –
Briefs
You can execute the command git remote -v
and it will get you the remote repository urls from where you have cloned.
origin https://github.abc.biz/hvardhan/test-repo.git (fetch)
origin https://github.abc.biz/hvardhan/test-repo.git (push)
The hvardhan
in the url denotes the fork was of the user with username hvardhan
.
Yes, do this:
(meta_learning) brandomiranda~/proverbot9001 ❯ git config --get remote.origin.url
[email protected]: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. –
Briefs
© 2022 - 2024 — McMap. All rights reserved.
git config --get remote.origin.url
– Calista