Lolly
Lolly

Reputation: 36372

Using `git checkout -b` with and without a branch starting point

I am new to Git, I want to know the difference between two commands.

`git checkout -b <branch-name>`
`git checkout -b <branch-name> origin/master`

If I execute the first command, how does Git create the branch? Will the branch be created from local master or remote master?

Upvotes: 16

Views: 7429

Answers (1)

Mat
Mat

Reputation: 206659

If you don't specify a starting point, the new branch is created from what you currently have checked out (the current HEAD).

git-checkout:

git checkout -b|-B <new_branch> [<start point>]

Specifying -b causes a new branch to be created as if git-branch(1) were called and then checked out.

And git-branch:

[...] The command’s second form creates a new branch head named <branchname> which points to the current HEAD, or <start-point> if given.

Upvotes: 16

Related Questions