How to create an orphan branch from Github API?

I want to create a gh-pages branch from the Github API. Is there an easy way to do this?

If not, how do I create an orphan branch from the Github API?

+6
source share
2 answers

You can create a branch using Create Link in the API part. I am not sure, however, if you can create an orphan branch with this or if the API will prevent this.

In fact, testing with curl does not work:

 curl -X POST -u sigmavirus24 https://api.github.com/repos/sigmavirus24/github3.py/github3.py/refs -d '{"ref":"refs/heads/orphaned"}' curl -X POST -u sigmavirus24 https://api.github.com/repos/sigmavirus24/github3.py/github3.py/refs -d '{"ref":"refs/heads/orphaned", "sha":""}' 

Both are returning:

 {"message": "Reference update failed"} 

I tried with and without the Content-Type header ( -H "Content-Type: application/json" ), but did not work.

From this insignificant experiment, it seems you cannot create an orphaned branch through the API.

+1
source

This can be done as follows:

  • Check if branch exists
  • If not, then create a commit that references git to the empty SHA tree
  • Then create a link to this commit

You can find sample CoffeeScript sample code for how to do this from https://github.com/noflo/noflo-github/blob/master/components/CreateOrphanBranch.coffee#L31

Here is one such branch created this way: https://github.com/the-domains/example.net/tree/branch_1403616324001

Update : this method only works if there are previous child orphans in the git repository. If this is a newly created repo created using the GitHub API using the auto_init option, it will not work. I contacted GitHub about this.

+1
source

Source: https://habr.com/ru/post/952954/


All Articles