Is there a way to determine if my local clone is a fork of some github repo?
Asked Answered
B

3

7

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"?

Briefs answered 28/10, 2019 at 17:30 Comment(4)
I suppose that you should have matching commit IDs at the beginning of your local branch(es).Contend
do git config --get remote.origin.urlCalista
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
Could someone please add typical responses for the two cases fork and cloneEduino
R
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
}
Reaper answered 28/10, 2019 at 17:32 Comment(3)
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
R
-1

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.

Rus answered 20/6 at 3:46 Comment(0)
C
-4

Yes, do this:

(meta_learning) brandomiranda~/proverbot9001 ❯ git config --get remote.origin.url
[email protected]:brando90/proverbot9001.git
Calista answered 28/10, 2019 at 17:31 Comment(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.Briefs

© 2022 - 2024 — McMap. All rights reserved.