How to update a fork from it's original via the Github API
I don't have the inside scoop on this, so this might be a miss-feature that will be removed at some point. Until then:
Github makes available all commits across (I assume) the entire fork network; So APIs that accept commit hashes will be happy to work on hashes from the upstream, or across other forks (This is explicitly documented for repos/commits/compare and creating a pull requst).
So there are a couple of ways to update via APIs only:
Using Git data api: This will usually be the best option, if you don't change your fork's master.
- Get upstream ref
/repos/upstream/repo/git/refs/heads/master
, and get the hash from it - Update your fork PATCH
/repos/my/repo/git/refs/heads/master
with the same hash.
- Get upstream ref
Using a higher-level merge api: This will create a merge commit, which some people like.
- Get the upstream ref like before
- Create a merge to branch
master
in your repo.
Pull-request to yourself and merge it via api: This will end up creating not only a merge commit, but a PR as well.
- Create PR: POST to
/repos/your/repo/pulls
withhead = "upstream:master"
- Get the PR url from the response,
- Merge it: PUT to
/repos/your/repo/pulls/number/merge
- Create PR: POST to
It's possible that the "upstream:master" notation would also work for options 1 & 2, saving an API call.
Not possible currently, but I've gone ahead and added that to our API wishlist. :)