I have the following branches:
dependabot/npm_and_yarn/types/jest-28.1.3
dependabot/pip/django-environ-0.9.0
test-dependabot/test
I want to grep the first two branches:
dependabot/npm_and_yarn/types/jest-28.1.3
dependabot/pip/django-environ-0.9.0
I've tried the following solutions but no luck:
git branch | grep dependabot/
- grabs all 3 branchesgit branch | grep ^dependabot/
- grabs no branches
What is the correct grep regex for this use case? The string start character ^
doesn't seem to be working correctly here?
CodePudding user response:
Check with a leading space before your branch name (you can have a leading *
if it is the current branch)
git branch|grep "\s\ dependabot/"
More formal a line starting with an optional * then one or several spaces before your branch name
git branch|grep "^\*\?\s\ dependabot/"
CodePudding user response:
You may use this git grep
:
git branch | grep '^[*[:blank:]]*dependabot/'
[[:blank:]]*
matches 0 or more whitespaces or *
after matching line start with ^