首页 > 解决方案 > 切换到新的 git 分支时 -b 和 -B 有区别吗?

问题描述

这可能是一个非常小的问题。我注意到有人在互联网上打字-B而不是-b在切换到新分支时。

git checkout -B new_branch

含义是什么,何时使用大写 B。如果-D我们使用大写 D 标志强制删除。大写B会发生什么。

Force deletion:
git branch -D local_branch

我尝试查看这些很棒的git Flight Rules但没有找到任何东西。

任何帮助,将不胜感激。

标签: githubgitlabgit

解决方案


From git checkout --help:

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. In this case you can use the --track or --no-track
           options, which will be passed to git branch. As a convenience, --track without
           -b implies branch creation; see the description of --track below.

           If -B is given, <new_branch> is created if it doesn’t exist; otherwise, it is
           reset.

推荐阅读