gh icon indicating copy to clipboard operation
gh copied to clipboard

github forks

Open barak opened this issue 7 years ago • 6 comments

I often have repos with multiple remotes corresponding to forks on github. It would be nice if gh had a sensible way to deal with that.

I can think of a couple ideas, e.g., if you gh foo bar when github.com/foo/bar is a fork of github.com/fu/bar which is already gh'ed, then create a symlink and do a git remote add fu xxx; git fetch fu. Or maybe do this only after user confirmation?

As a generalization, it would be nice to be able to gh-forks a repo and have it cloned with all forks added as remotes, and to be able to update this when new forks are created.

barak avatar Nov 07 '16 13:11 barak

I've ran into this as well. I like your proposal, but I'm unsure how to know if something is a fork. I would probably have to call out to some kind of tool to detect it.

I would also like to figure out how to manage the remotes when you're in a forked repo. I do it differently each time and haven't settled on a consistent workflow that works for me.

jdx avatar Jan 29 '18 23:01 jdx

I believe that forks are managed via the websites (Github, Gitlab, Bitbucket, etc) and not by git itself.

If you want to implement with api requests Github is pretty straight forward.

  1. From api docs https://developer.github.com/v3/repos/forks/
  2. Example showing forks for this repo: https://api.github.com/repos/jdxcode/gh/forks

Gitlab is a little more difficult,

  1. Get the id by searching the project name https://gitlab.com/api/v4/users/jdxcode/projects?search=readme
  2. Get forks from the id https://gitlab.com/api/v4/projects/6598339/forks

I can lookup bitbucket or other websites if this info is helpful.

Lastly, if you have a Github project and you want it to check Gitlab or Bitbucket automagically. This app may need to guess that the same username exists for those different websites and fail gracefully.

Let me know if this helps. Or maybe this is no longer an issue I am kind of late to the party. Happy to assist further.

MichaelDimmitt avatar Oct 11 '18 13:10 MichaelDimmitt

#36 may give some start for this feature.

tsvayer avatar Oct 14 '18 09:10 tsvayer

#38 PR partially deals with this issue.

tsvayer avatar Oct 16 '18 15:10 tsvayer

If you are on a repo that is a fork. The normal api request for repo has a parent key to tell you what it was forked from. https://api.github.com/repos/ahazem/gh source: https://stackoverflow.com/a/18586164

Get all the forks using github api:

  1. check the repo for a parent repo https://api.github.com/repos/ahazem/gh
  2. request forks If no parent repo, (example imagines there was no parent repo.) https://api.github.com/repos/ahazem/gh/forks If parent repo exists use the parent repo in the api request. https://api.github.com/repos/jdxcode/gh/forks

MichaelDimmitt avatar Oct 25 '18 04:10 MichaelDimmitt

These commands works pretty well, Implemented on a mac which comes with python by default. Using python to parse the json response.

curl -s 'https://api.github.com/repos/ahazem/gh' | \
python -c "import sys, json; print json.load(sys.stdin)['parent']['forks_url']"

expected result: https://api.github.com/repos/jdxcode/gh/forks

curl -s 'https://api.github.com/repos/ahazem/gh' | \
python -c "import sys, json; print json.load(sys.stdin)['parent']['html_url']"

expected result: https://github.com/jdxcode/gh

MichaelDimmitt avatar Oct 25 '18 04:10 MichaelDimmitt