在Windows操作系统下,我使用git Bash克隆一个git仓库。我使用Git Bash操作git branch
和git 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 branch
和git branch -l
是一样的。你是对的,在-l
选项的描述中没有提到它默认为本地分支。但是,git branch
的文档以您的问题的答案开始:
如果给出了
--list
,或者如果没有非选项参数,则列出现有分支;…选项-r
列出远程跟踪分支,选项-a
同时显示本地和远程分支。
有时一个表格可以让你更容易看到。
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
。