Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an orphan branch from the Github API?

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?

like image 772
Daniel X Moore Avatar asked Sep 02 '13 03:09

Daniel X Moore


1 Answers

It is possible to do this by:

  1. Check whether the branch already exists
  2. If not, then create a commit that refers to git's empty tree SHA
  3. Then create a ref to that commit

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.

like image 131
bergie Avatar answered Oct 23 '22 00:10

bergie