git branch和git branch之间的差异- 1

  • 本文关键字:git branch 之间 git
  • 更新时间 :
  • 英文 :


在Windows操作系统下,我使用git Bash克隆一个git仓库。我使用Git Bash操作git branchgit branch -l,发现它们都列出了local分支机构名称。当我操作git branch -h时,它列出了-l, --list list branch names,但它没有提到-l列出了本地分支。我不知道它们的功能是否相同

git branch命令用于列出、创建和删除分支。默认情况下,它列出存储库中所有本地分支的名称。例如,运行不带任何附加选项的git branch将显示所有本地分支的列表:

$ git branch
Yourbranch1
Yourbranch2

- l选项用于将分支列表限制为与指定模式匹配的分支。例如,运行git branch -l "feat*"将列出以前缀" feature ">

开头的所有分支。
$ git branch -l "feat*"
feat/feature1
feat/feature2

是的,git branchgit branch -l是一样的。你是对的,在-l选项的描述中没有提到它默认为本地分支。但是,git branch的文档以您的问题的答案开始:

如果给出了--list,或者如果没有非选项参数,则列出现有分支;…选项-r列出远程跟踪分支,选项-a同时显示本地和远程分支。

有时一个表格可以让你更容易看到。

显示远程xx

git branch --list列出分支。git branch做的更多(如前所述git branch -h的选项)。例如,

$ git branch
* feature
main
temp
test
$ git branch main
fatal: A branch named 'main' already exists.
$ git branch -l main
main
$ git branch -l main feature
* feature
main

在脚本中我可以检查

$ git branch -l main master
* main

查看repo使用的是main还是master,并在其他命令中使用该结果,例如git pull origin main

最新更新