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>
Yes, you can create sub-branches to any branch. Lets say you have a master branch then from the master branch you can create a sub-branch. You can further create sub-branches from this child branch.
Git offers a feature referred to as a worktree, and what it does is allow you to have multiple branches running at the same time. It does this by creating a new directory for you with a copy of your git repository that is synced between the two directories where they are stored.
Push a new Git branch to a remote repoClone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With