How do I search for branch names in Git?

GitSearch

Git Problem Overview


I'd like to find a specific branch, and I know that its name would contain a specific substring (the id of the issue from our bug tracker), but I don't know the whole name of the branch (this is what I want to find out).

How can I search for this branch?

Git Solutions


Solution 1 - Git

git branch --all | grep <id>

Solution 2 - Git

Git 1.7.8 offers a solution without using grep:

git branch --list <pattern> and in bash git branch --list '<pattern>' with quotes around pattern.

This works with wildcards (*) as well, so you can do use git branch --list *<id>* to find your branch.

This filters the list of branch names returned by the rest of your git branch command (for example, local branches only by default, all branches with git branch -a --list <pattern>, etc.).

Solution 3 - Git

git branch -a | grep selector

Or

git branch -r | grep selector

-a shows all local and remote branches, while -r shows only remote branches.

Solution 4 - Git

Find the branch Name where having specified text

git branch --list *text*

For Ex- I want to find the branch that has "production" word

git branch --list *production*

Solution 5 - Git

Building of the answers that others have given, I added this to my .gitconfig

[alias]
  findb = "!f(){ git branch -ra | grep $1; }; f"

So on the command line I can type git findb BUG-123

Solution 6 - Git

Assuming that you are using GitHub, there is a drop down list for your branches and for tags in that drop down menu there is a search area.

You can use that search area to search for your branch name.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser650309View Question on Stackoverflow
Solution 1 - GitEvil ToadView Answer on Stackoverflow
Solution 2 - GitCalvin LiView Answer on Stackoverflow
Solution 3 - GitRoy ShmuliView Answer on Stackoverflow
Solution 4 - Gituser6609090View Answer on Stackoverflow
Solution 5 - GitSnekseView Answer on Stackoverflow
Solution 6 - GitFosterdn007View Answer on Stackoverflow