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?
Checkout a New Branch or Reset a Branch to a Start PointIf the BRANCH-NAME branch doesn't exist, Git will create it and start it at START-POINT . If the BRANCH-NAME branch already exists, then Git resets the branch to START-POINT . This is equivalent to running git branch with -f .
In order to checkout a remote branch you have to first fetch the contents of the branch. In modern versions of Git, you can then checkout the remote branch like a local branch. Older versions of Git require the creation of a new branch based on the remote .
Use the git switch - (Or git checkout - ) to switch to the previous branch you were working with. This is pretty similar to the cd - command, which is used to switch to the previous directory.
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 currentHEAD
, or<start-point>
if given.
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