How to update a fork from it's original via the Github API

你离开我真会死。 提交于 2019-12-10 13:21:50

问题


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?


回答1:


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:

  1. Using Git data api: This will usually be the best option, if you don't change your fork's master.

    1. Get upstream ref /repos/upstream/repo/git/refs/heads/master, and get the hash from it
    2. Update your fork PATCH /repos/my/repo/git/refs/heads/master with the same hash.
  2. Using a higher-level merge api: This will create a merge commit, which some people like.

    1. Get the upstream ref like before
    2. Create a merge to branch master in your repo.
  3. Pull-request to yourself and merge it via api: This will end up creating not only a merge commit, but a PR as well.

    1. Create PR: POST to /repos/your/repo/pulls with head = "upstream:master"
    2. Get the PR url from the response,
    3. Merge it: PUT to /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.




回答2:


Not possible currently, but I've gone ahead and added that to our API wishlist. :)



来源:https://stackoverflow.com/questions/26846667/how-to-update-a-fork-from-its-original-via-the-github-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!