Git:如何只列出本地分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12370714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: How do I list only local branches?
提问by munyengm
git branch -a
shows both remote and local branches.
git branch -a
显示远程和本地分支。
git branch -r
shows remote branches.
git branch -r
显示远程分支。
Is there a way to list just the local branches?
有没有办法只列出本地分支机构?
回答by gertvdijk
Just git branch
without options.
只是git branch
没有选择。
From the manpage:
从联机帮助页:
With no arguments, existing branches are listed and the current branch will be highlighted with an asterisk.
没有参数,现有分支被列出,当前分支将用星号突出显示。
回答by c00kiemon5ter
just the plain command
只是简单的命令
git branch
回答by shortduck
git branch -a
- Allbranches.
git branch -a
-所有分支机构。
git branch -r
- Remotebranches only.
git branch -r
-仅限远程分支。
git branch -l
or git branch
- Localbranches only.
git branch -l
或git branch
-仅限本地分支机构。
回答by John Marter
If the leading asterisk is a problem, I pipe the git branch
as follows
如果前导星号有问题,我git branch
按如下方式进行管道传输
git branch | awk -F ' +' '! /\(no branch\)/ {print }'
This also eliminates the '(no branch)' line that shows up when you have detached head.
这也消除了分离头时出现的“(无分支)”线。
回答by Victor Yarema
One of the most straightforward ways to do it is
最直接的方法之一是
git for-each-ref --format='%(refname:short)' refs/heads/
This works perfectly for scripts as well.
这也适用于脚本。
回答by Shnatsel
Here's how to list local branches that do not have a remote branch in origin with the same name:
以下是如何列出在源中没有具有相同名称的远程分支的本地分支:
git branch | sed 's|* | |' | sort > local
git branch -r | sed 's|origin/||' | sort > remote
comm -23 local remote
回答by jlsanchezr
Other way for get a list just local branch is:
获取本地分支列表的其他方法是:
git branch -a | grep -v 'remotes'
回答by Samwar
There's a great answerto a post about how to delete local only branches. In it, the fellow builds a command to list out the local branches:
关于如何删除仅本地分支的帖子有一个很好的答案。在其中,该家伙构建了一个命令来列出本地分支:
git branch -vv | cut -c 3- | awk '$3 !~/\[/ { print $1 }'
git branch -vv | cut -c 3- | awk '$3 !~/\[/ { print $1 }'
The answer has a great explanation about how this command was derived, so I would suggest you go and read that post.
答案对这个命令是如何派生的有很好的解释,所以我建议你去阅读那篇文章。
回答by RBT
To complement @gertvdijk's answer - I'm adding few screenshots in case it helps someone quick.
为了补充@gertvdijk 的回答 - 我添加了一些截图,以防它快速帮助某人。
On my git bash shell
在我的 git bash shell 上
git branch
git 分支
command without any parameters shows all my local branches. The current branch which is currently checked out is shown in differentcolor (green) along with an asterisk (*) prefix which is really intuitive.
不带任何参数的命令显示我所有的本地分支。当前签出的当前分支以不同的颜色(绿色)以及星号 (*) 前缀显示,这非常直观。
When you try to see all branches including the remote branches using
当您尝试使用以下命令查看包括远程分支在内的所有分支时
git branch -a
git 分支 -a
command then remote branches which aren't checked out yet are shown in red color:
命令然后尚未签出的远程分支以红色显示: