Brad Parks Brad Parks - 4 months ago 9
Git Question

Git - can I determine from the command line where a forked repo was forked from?

I've got a forked github repo on my machine, I'll call

MYFORK
.

It was forked from a repo I'll call
MAIN_REPO


Is there a generic way from the command line to find out where
MYFORK
came from? ie the answer should be
MAIN_REPO
, not the url to my fork on github.

I'm open to git or command line github specific solutions, and am interested in solutions that don't require me to have manually added an "upstream" at some point, as implied here.

Answer

It's a bit of work, but you could probably use e.g. octokit.rb or the github_api gem to write a small Ruby script that accesses the GitHub API to list all your repositories, searching for the one whose url field matches your origin remote, and for that object again look at the parent object's url field. That gives you the repository your repository was forked from. If you're interested in the ultimate source of all forks of forks, use the source object's url instead.

Comments