I have the following git branches
foo
bar
foobar
feature/foo
feature/bar
feature/buzz
How would you do a for loop over all branches that start with the word 'feature/' ?
When I try the following, it strangely prints out more than just the git branches.
for i in $(git branch --list "feature/*"); do echo $i; done;
stuff.txt
icon.jpg
morestuff.txt
Vagrantfile
feature/foo
feature/bar
feature/buzz
"We actively discourage against use of any Porcelain command, including git branch, in scripts" - from the Git Maintainer's Blog
You want to use something like
git for-each-ref --format='%(refname:short)' refs/heads/feature/
which will work fine inside a for br in $()
construct
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With