gh
gh copied to clipboard
github forks
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.
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.
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.
- From api docs https://developer.github.com/v3/repos/forks/
- Example showing forks for this repo: https://api.github.com/repos/jdxcode/gh/forks
Gitlab is a little more difficult,
- Get the id by searching the project name https://gitlab.com/api/v4/users/jdxcode/projects?search=readme
- 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.
#36 may give some start for this feature.
#38 PR partially deals with this issue.
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:
- check the repo for a parent repo https://api.github.com/repos/ahazem/gh
- 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
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