如何显示存储库中的所有分支? [英] How can I show all the branches in a repository?

查看:69
本文介绍了如何显示存储库中的所有分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Git存储库.如何显示其所有分支?

I have a Git repository. How can I show all its branches?

以下两个命令是否应该显示所有分支?如果是,为什么它们不显示分支 master ?当我问

Are the following two commands supposed to show all the branches? If yes, why do they not show branch master? I was under the impression that the repository doesn't have branch master, when asking https://stackoverflow.com/questions/54160690/will-pushing-a-new-branch-to-another-repository-create-an-upstream-branch-and-re.

$ git branch -a
  mongodbutils

$ git show-branch
[mongodbutils] mongodbutils

$ ls .git/refs/heads/
mongodbutils

以下命令为什么提及分支 master ?

Why does the following command mention branch master?

$ git show
fatal: your current branch 'master' does not have any commits yet

如何显示存储库中的所有分支(在这种情况下,包括 master )?我认为这很重要,否则,我会有同样的错误印象.

How can I show all the branches (including master in this case) in a repository? I think it is important, or else, I will have the same false impression.

注意:该存储库是通过 git init 一个空目录创建的,然后我 git push 一个分支 mongodbutils 从另一个分支进入了这个目录分支.

Note: the repository was created by git init an empty directory, and then I git push a branch mongodbutils from another branch into this branch.

推荐答案

作为 的文档> git branch 解释说, git branch --all (或 -a )列出了本地存储库中的所有分支,包括本地分支和分支分支.远程跟踪分支.

As the documentation of git branch explains, git branch --all (or -a) lists all the branches from the local repository, both the local and the remote tracking branches.

Git分支只是指向提交的指针.一个新的存储库(仅使用 git init 创建)不包含任何提交.新仓库中的当前分支是 master ,但是 master 分支实际上并不存在.实际上,新的存储库不包含任何分支.

A Git branch is just a pointer to a commit. A new repository (just created with git init) does not contain any commits. The current branch on a new repo is master but the master branch does not actually exist. In fact, a new repository does not contain any branch.

master 分支是在创建第一次提交时创建的.或从远程存储库中提取时.

The master branch is created when the first commit is created. Or when it is pulled from a remote repository.

由于您没有创建任何提交,也没有提取 master 分支,因此它在您的存储库中不存在.您列出的两个命令都向您展示了这件事.

Since you didn't create any commit and also didn't pull the master branch, it does not exist in your repo. Both commands you listed show you this thing.

git branch -a 是您要用来列出分支的那个.

git branch -a is the one you want to use to list the branches.

git show-branch 设计用于脚本和GUI工具.

git show-branch is designed to be used by scripts and GUI tools.

这篇关于如何显示存储库中的所有分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆