0

How to fork a Repo via GitHub API?

I'm looking at GitHub Fork API doc at https://developer.github.com/v3/repos/forks/#create-a-fork and I'm quite confused as how to do it.

Create a fork
Create a fork for the authenticated user.

POST /repos/:owner/:repo/forks

So if I want to clone github.com/neurobin/shc as mine, github.com/myghid/shc, what exact curl command I should be using? Thx.

1 Answer 1

2

In order to fork a repo you must query the github API endpoint. Here's an example, assuming that you have created your github API token already:

curl -X POST -u "<github_username>:<github_token>" \
    "https://api.github.com/repos/neurobin/shc/forks"

When you will ever see extra parameters in github API, you can pass them inside the JSON object. In case of organization parameter for the fork API, full query would look like this:

curl -X POST -u "<github_username>:<github_token>" \
    -d "{\"organization\": \"your_org_here\"}" \
    "https://api.github.com/repos/neurobin/shc/forks"

After that you can clone it with simple:

git clone https://github.com/your_github_nick/shc
2
  • Thanks! would there be any differences if the repo is owned/under an organization instead of an end user? e.g., what if I want to clone a repo into a github organization? How to specify the organization string, the optional parameter to specify the organization name if forking into an organization? Thanks
    – xpt
    Oct 14, 2017 at 14:05
  • @xpt i updated the answer Oct 16, 2017 at 3:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .