如何在Git中搜索分支名称?
我想找到一个特定的分支,我知道它的名称将包含一个特定的子字符串(来自我们的错误跟踪器的问题的ID),但是我不知道该分支的全名(这就是我的意思) 想找出来)。
如何搜索该分支?
user650309 asked 2019-11-15T22:07:03Z
5个解决方案
74 votes
git branch --all | grep <id>
40 votes
Git 1.7.8提供了更好的解决方案:
git branch
无需转到git branch
。
这也适用于通配符(git branch
),因此您可以使用git branch -a --list <pattern>
查找分支。
这将过滤其余git branch
命令返回的分支名称列表(例如,仅默认情况下为本地分支,所有具有git branch -a --list <pattern>
的分支,等等)。
9 votes
git branch -a | grep selector
要么
git branch -r | grep selector
-a显示所有本地和远程分支,而-r仅显示远程分支。
7 votes
建立其他人给出的答案后,我将此添加到我的git findb BUG-123
中
[alias]
findb = "!f(){ git branch -ra | grep $1; }; f"
所以在命令行上我可以输入git findb BUG-123
0 votes
假设您使用的是GitHub,则有一个分支的下拉列表,并且该下拉菜单中的标签有一个搜索区域。
您可以使用该搜索区域来搜索您的分支名称。