简体   繁体   English

Git命令:git checkout -b和有什么不一样 <branch><remote branch> 和git分支 <branch><remote branch> ?

[英]Git command: what is the difference between git checkout -b <branch> <remote branch> and git branch <branch> <remote branch>?

When you create a new branch which already exits in a remote repository but don't in a local repository, probably you can run these two commands: git checkout -b hotfix origin/hotfix and git branch hotfix origin/hotfix where hotfix is exactly the branch I hypothesized. 当您创建一个已经在远程存储库中退出但不在本地存储库中的新分支时,可能可以运行以下两个命令: git checkout -b hotfix origin/hotfixgit branch hotfix origin/hotfix ,其中hotfix正是我假设的分支。 So, what is exactly the difference between these two commands? 那么,这两个命令之间到底有什么区别? It seems that both makes a new branch already tracking the upstream branch. 似乎两者都使得一个新分支已经在跟踪上游分支。

Can anyone explain it? 有人可以解释吗?

git branch only create the branch, but head still remain pointed to previous branch .. for example if your current branch was master and you execute git branch abc, abc branch will be created but current branch still be master. git branch只创建分支,但是头部仍然指向上一个分支..例如,如果您当前的分支是master并执行git branch abc,则将创建abc分支,但当前分支仍然是master。

git checkout -b abc, first create the branch plus checkout on top of branch creation... so if master was current branch, post execution abc will be current branch git checkout -b abc,首先创建分支,再在分支创建之上添加checkout ...因此,如果master是当前分支,则执行后abc将是当前分支

yes both makes a new branch.. but first first one is creation of branch + checkout of that branch 是的,两个都创建了一个新分支。.但是第一个第一个是创建分支+签出该分支

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM