I've created a fork of a github repository via the github API. Now, later on, I want to pull any updates from the origin repository into the fork. This should always be a fast-forward in my use case. I have read access to the origin repository and read-write to the fork.
I thought of maybe creating a Pull Request then accepting (both of which you can do via the API) but this creates noise (Pull Requests being created and destroyed) and just doesn't seem right.
Is there any way to do this via the 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.
/repos/upstream/repo/git/refs/heads/master
, and get the hash from it/repos/my/repo/git/refs/heads/master
with the same hash.Using a higher-level merge api: This will create a merge commit, which some people like.
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.
/repos/your/repo/pulls
with head = "upstream:master"
/repos/your/repo/pulls/number/merge
It's possible that the "upstream:master" notation would also work for options 1 & 2, saving an API call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With