How to create a branch from default branch using github APIs ?

Hi,

I have scenario, I want to create a remote branch in git from the develop branch using APIs, I saw in API developer’s documentation. We can create branch by giving the commit number, but here I want to create a branch from my default branch not based on the commit number. Please give your ideas.

Thanks,

Mani.

A branch is a type of “ref” in git terminology. A “ref” is a reference to a commit. So if you want to create a branch, you have to tell it what it is referring to. Since a ref always refers to a commit, you have to give it a commit hash to create it. If you want to create a new branch that refers to the same commit as some other branch, you have to find out what commit the other branch refers to, then create the new branch referring to the same commit.

In other words:

  1. Find out what commit the old branch refers to
  2. Take the commit hash
  3. Create the new branch with the commit hash

I hope that helps!