Skip to content

Instantly share code, notes, and snippets.



Last active Oct 13, 2020
What would you like to do?
Create a branch on Github without access to a local git repo using

Ever had the need to create a branch in a repo on Github without wanting (or being able) to access a local repo?

With the aid of the Github API and this is a piece of cake!

Just follow these steps:

  1. Open

  2. Find the revision you want to branch from. Either on Github itself or by doing a GET request from Hurl:<AUTHOR>/<REPO>/git/refs/heads

  3. Copy the revision hash

  4. Do a POST request from Hurl to<AUTHOR>/<REPO>/git/refs with the following as the POST body :

       "ref": "refs/heads/<NEW-BRANCH-NAME>",
       "sha": "<HASH-TO-BRANCH-FROM>"

    (obviously replacing the <NEW-BRANCH-NAME> with the name your want the new branch to have and the <HASH-TO-BRANCH-FROM> with, you know, the hash of the revision you want to branch from)

    You will need to use HTTP basic and fill in your Github credentials to access the Github API.

  5. Press the Send button and your branch will be created!

The situation I ran into, was that I found a web app that had a demo but the demo wasn't hosted anywhere. So all I needed to do was clone the repo, create a branches called gh-pages (which automatically creates a site hosted by github) and I could watch the demo online without any local repo.

I've also used this to submit (simple) fixes to repos that require a pull-request from a branch that is not master.

Do you have any other use cases or maybe any other service than Hurl that could be used?

Let me know in the comments!


This comment has been minimized.

Copy link

@kelvinabrokwa kelvinabrokwa commented Jul 3, 2015

This was super helpful! Thank you!


This comment has been minimized.

Copy link

@auwsome auwsome commented Aug 23, 2015

Hi, I created a Python script and function forked from your repo. Thank you, this helped me test the GitHub API was working without Python errors. It is at:
"Create a branch on Github using API and Python"


This comment has been minimized.

Copy link

@techytushar techytushar commented Jun 28, 2018

Thank You, it was very helpful 🙂


This comment has been minimized.

Copy link

@AhmedAbdElfatah999 AhmedAbdElfatah999 commented Mar 31, 2020

I Have An Error :Unexpected Token ":"
How Can I Solve It ??


This comment has been minimized.

Copy link
Owner Author

@Potherca Potherca commented Apr 6, 2020

@AhmedAbdElfatah999 Without any further information your question would be hard to answer. This also isn't really the right place to ask, so I doubt you'll be able to get a decent response here. You might want to try asking your question on or at the gist that has the code your are running?


This comment has been minimized.

Copy link

@foutoucour foutoucour commented Oct 13, 2020


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.