Rahul
Rahul

Reputation: 47146

how to create a branch for a branch in git?

There is an branch xyz for my master branch. I wanna create a new branch for the branch xyz. How can I do this?

Upvotes: 2

Views: 440

Answers (3)

Adam Dymitruk
Adam Dymitruk

Reputation: 129762

git branch new-branch-name-you-want xyz

Upvotes: 0

Cascabel
Cascabel

Reputation: 497602

The primary ways to create branches are:

git branch <name> [start-point]
git checkout -b <name> [start-point]

The first just creates a branch, while the second creates and checks it out. If the start point is provided (e.g. master) then the branch is created at that point. If it's not, then it's created at whatever you currently have checked out.

In either case, it's really referring to the commit; there's no association between branches that's created. That is, git branch xyz master doesn't create a branch "for" master, it just creates a branch at the commit master is currently at. If you never merge one back into the other, they'll never know about each other.

Upvotes: 5

zoul
zoul

Reputation: 104125

The branch is always created from the current branch. In other words, there’s nothing special here, simply git checkout -b xyz-branch while on xyz.

Upvotes: 1

Related Questions