As we know, I create a local branch
branch I can use:
git checkout -b branch
But there is a git checkout -b branch origin/branch
I do't know whats the difference between them, who can tell me about it? Does this command will create a remote origin/branch
?
EDIT
I have three questions:
1.Whether the git checkout -b branch origin/branch
create a branch in local repo?
2.Does git checkout -b branch origin/branch
create a origin branch for remote repo?
3.Or is the git checkout -b branch origin/branch
is create a branch from local repo master branch, and git checkout -b branch
create a branch from current branch?
1.Whether the git checkout -b branch origin/branch create a branch in local repo?
Yes.
2.Does git checkout -b branch origin/branch create a origin branch for remote repo?
No, it creates a local branch which is identical to origin/branch (status of last pull)
3.Or is the git checkout -b branch origin/branch is create a branch from local repo master branch, and git checkout -b branch create a branch from current branch?
The difference is the "what will be in the new branch". origin/branch refers to a local reference (can't be modified!) of the remote repo, branch is a local branch.
Have a look at the very good explanations in the git book
As per the manual :
git checkout -b|-B <new_branch> [<start point>]
Specifying
-b
causes a new branch to be created as if git-branch were called and then checked out. […]
So calling git checkout -b new_branch
or git checkout -b new_branch start_point
is equivalent to the following:
git branch new_branch
git checkout new_branch
# or
git branch new_branch <start_point>
git checkout foo
So let's check git-branch
on what happens with that start point:
The command's second form creates a new branch head named
<branchname>
which points to the currentHEAD
, or<start-point>
if given.
Not specifying a start point means that the start point is HEAD
, so git branch new_branch
is equivalent to git branch new_branch HEAD
.
So what does git branch new_branch start_point
do? Create a new branch new_branch
that points at the commit specified by start_point
. If you don't specify one, then that will be HEAD
which is the currently checked out commit.
To sum this up: git checkout -b branch
will create and check out a new branch branch
that is at the exact same location you currently are at. git checkout -b branch origin/branch
will create and check out a new branch branch
that points at origin/branch
which is the local copy of the remote branch branch
on the origin
remote.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.