Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Grep for git branches starting with string

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • git branch | grep dependabot/ – grabs all 3 branches
  • git 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?

>Solution :

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/"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading