11

In my repository, I have a master branch and then a staging branch coming out of master branch. Now I need to add a third branch that should come out from staging branch. That means I need a branch coming out of another branch. Can anyone help in this?

The syntax I used for creating branch is like this:

git branch <name_of_your_new_branch>

git push origin <name_of_your_new_branch>

git checkout <name_of_your_new_branch>
Rahul Dolas
  • 145
  • 1
  • 1
  • 8

1 Answers1

12

This can create your branch locally:

git checkout staging
git checkout -b newBranch

or, one line:

git checkout -b newBranch staging

That will start from the current HEAD of staging, but note that a branch doesn't really comes from another branch: it comes from a commit (and that commit can be part of multiple branches).

You can then push your new branch, tracking the the remote branch in one command:

git push -u origin newBranch    
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250