Reputation: 11
If I create a branch in the terminal
git checkout -b 'test_branch2'
this branch will be inherited from the branch on which I was before that (in my case, test_branch1
).
I need to create a branch inherited from master
in the terminal, how do I do that?
Upvotes: 1
Views: 561
Reputation: 23144
A branch in Git is not inherently related to any other branch.
A branch is only a "pointer" or "bookmark" to a commit and therefore refers to that commit and all of its ancestors.
The command
git checkout -b 'test_branch2'
creates a new branch which points to the commit that is currently "active" (the one which the special HEAD
reference points to).
The command accepts as additional argument the name of, or reference to, a particular commit. Such a reference can for example be another branch.
So in order to create a new branch that points to the same commit as the branch master
currently does, you can use
git checkout -b test_branch2 master
(the quotes aren't required in this case, by the way)
Note again, this doesn't make test_branch2
in any way related to master
, they only happen to point to the same commit now, but that could change in the future.
Upvotes: 2