How to create a branch from an existing branch in a repository in github using python or curl

I am trying to use curl commands to do this scenario. but i am getting 404 error for my post request.

My curl commands is 

curl -i -H ‘Authorization: token **********************************’ </strong>

    -d '{ </strong>

        “ref”: “refs/heads/new_branch”, </strong>

        “sha”: “11111122222233333344444” </strong>

      }’ </strong>

sha - hash of the exsiting branch in the repository

ref - name of the new branch

need help to resolve this

1 Like

Hi @arun0910,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our Community organized so users can more easily find information.

As you’ll notice, your Topic is now in the How to use Git and GitHub board. No action is needed on your part; you can continue the conversation as normal here.


Hi @arun0910,

Generally, the format of your request looks to be right. Without being able to look at your repository directly, my guess would be that your Personal Access Token is incorrect or does not have the right scope for this operation, or this SHA is incorrect.

Are you able to Get all references using the API?



I was able to create a branch from the existing branch using the same command. The issue was, i initially wrote the commands in notepad and  copied that command to command line, so the quotes used in the notepad is not recogized by the command line, so i tried to type in the same command in command line  and it worked.


Hi @arun0910,

Glad to hear that worked for you! Smart quotes which are the special form of quotation marks that many word processors use can cause this problem a lot. If you create API calls often, you may want to work in a text editor that specializes in working on code like Atom or use something like Postman which will help you craft API calls in a graphical interface.