Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github forks #30

Open
barak opened this issue Nov 7, 2016 · 6 comments
Open

github forks #30

barak opened this issue Nov 7, 2016 · 6 comments

Comments

@barak
Copy link

barak commented Nov 7, 2016

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.

@jdx
Copy link
Owner

jdx commented Jan 29, 2018

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.

@MichaelDimmitt
Copy link

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.

@tsvayer
Copy link
Contributor

tsvayer commented Oct 14, 2018

#36 may give some start for this feature.

@tsvayer
Copy link
Contributor

tsvayer commented Oct 16, 2018

#38 PR partially deals with this issue.

@MichaelDimmitt
Copy link

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
Copy link

MichaelDimmitt commented Oct 25, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants