Git:我如何只列出本地分支机构?

本文翻译自: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. 这也适用于脚本。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值