Skip to content

Instantly share code, notes, and snippets.

@Potherca
Last active November 27, 2023 17:44
Show Gist options
  • Star 47 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save Potherca/3964930 to your computer and use it in GitHub Desktop.
Save Potherca/3964930 to your computer and use it in GitHub Desktop.
Create a branch on Github without access to a local git repo using http://hurl.eu/

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 any online request app this is a piece of cake!

Just follow these steps:

  1. Open an online request app (like apirequest.io, hurl.it pipedream.com, reqbin.com, or webhook.site)

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

  3. Copy the revision hash

  4. Do a POST request from Hurl to https://api.github.com/repos/<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!

@kelvinabrokwa
Copy link

This was super helpful! Thank you!

@auwsome
Copy link

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"
https://gist.github.com/auwsome/123ae1f493dfd9b08434

@techytushar
Copy link

Thank You, it was very helpful 🙂

@AhmedAbdElfatah999
Copy link

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

@Potherca
Copy link
Author

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 https://stackoverflow.com/ or at the gist that has the code your are running?

@foutoucour
Copy link

Thanks

@Immanuelbh
Copy link

hurl link is down

@Potherca
Copy link
Author

Yeah. Sadly, it been down for ages. I was hoping it might come back online... Anyway, I've changed the gist to suggest various alternatives.

@Immanuelbh
Copy link

thank you! works great

@SiddharthShyniben
Copy link

Thank you!
After a great deal of head scratching and reading through git internals, I found this gist

@Potherca
Copy link
Author

@SiddharthShyniben Glad I could be of service!

@nawarkhede
Copy link

nawarkhede commented Jun 9, 2021

Here is working snippet in python https://stackoverflow.com/a/67891724/1246764

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment