Reputation: 15060
I want to create the gh-pages
branch from the Github API. Is there an easy way to do this?
If not, how would I create an orphan branch from the Github API?
Upvotes: 10
Views: 2261
Reputation: 930
It is possible to do this by:
You can find some CoffeeScript example code for how to do that 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 the git repository has previous orphan branches. If it is a newly-created repo created via GitHub's API using the auto_init
option it won't work. I've contacted GitHub about this.
Upvotes: 2
Reputation: 28747
You can create a branch via the Create a Reference part of the API. I'm not sure, however, if you can create an orphaned branch with that or if the API would prevent that.
In fact, testing it out with curl doesn't 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 return:
{"message": "Reference update failed"}
I tried with and without the Content-Type
header (-H "Content-Type: application/json"
) but neither work.
From that minor experimentation, it would appear you can not create an orphaned branch via the API.
Upvotes: 1