rich22 rich22 - 1 year ago 86
Git Question

How do you know which branch that a newly created branch will be based off of?

Consider the following scenario:

I create a branch from master, and call that branch1 and create another commit for that branch (b). Then I create another branch without merging branch1 with master, using

git checkout -b branch2
.

A) How would I know which branch, branch2 would be based off of? Would it automatically create the branch off of the master branch or off of branch a?

B) How would you create a branch off of the branch that the first part didn't cover (i.e.: if the answer to first part is that that creates a branch off of branch1, how do you create a branch off of master/viceversa?)

master --> a
\
\
branch1 --> b

(location of new branch?)

Answer Source

Git branch comes off your current branch (actually HEAD), by default.

If you want to specify where it branches from, specify the startpoint

git branch [--set-upstream | --track | --no-track] [-l] [-f] < branchname > [ <start-point> ]