本文翻译自:Git: How do I list only local branches?
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? 有没有办法列出当地的分支机构?
#1楼
参考:https://stackoom.com/question/puBe/Git-我如何只列出本地分支机构
#2楼
只是普通的命令
git branch
#3楼
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. 如果没有参数,则会列出现有分支,并使用星号突出显示当前分支。
#4楼
If the leading asterisk is a problem, I pipe the git branch
as follows 如果前导星号是个问题,我按如下方式管道git branch
git branch | awk -F ' +' '! /\(no branch\)/ {print $2}'
This also eliminates the '(no branch)' line that shows up when you have detached head. 这也消除了当你有分离头时出现的'(无分支)'线。
#5楼
获取列表的其他方式只是本地分支是:
git branch -a | grep -v 'remotes'
#6楼
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. 这也适用于脚本。