Alex
Alex

Reputation: 44305

How to create a github pull request from a forked repository back to the original repository using the github API?

In git/github I want to propose a change to a single file.

To do so, I

Now how can I programatically (via API) create a new pull request to merge the changes I have put in the forked repo to the original repo? How to do that?

The documentation only seems to handle the case when it is the same repository.

Upvotes: 0

Views: 1694

Answers (1)

Matt
Matt

Reputation: 13923

The documentation can be confusing. The following request will create a new pull request on FORKOWNER/THEREPO to merge FORKER:newbranch into FORKOWNER:main:

curl -X POST -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/FORKOWNER/THEREPO/pulls \
  -d '{"title":"XYZ", "body":"ABC", "head":"FORKER:newbranch", "base":"main"}'

This can also be done with the gh api command of the GitHub CLI:

gh api --method POST -H "Accept: application/vnd.github.v3+json" \
  repos/FORKOWNER/THEREPO/pulls \
  -f title='XYZ' -f body='ABC' -f head='FORKER:newbranch' -f base='main'

Or directly with the gh pr create command of the GitHub CLI:

gh pr create --repo FORKOWNER/THEREPO \
  --title "XYZ" --body "ABC" --head FORKER:newbranch --base main

Upvotes: 3

Related Questions