Is it possible to somehow use wildcards when specifying branch names in "git merge"?
For example, if I have:
sbos@malta:~/tmp/texterra$ git branch -r
origin/HEAD -> origin/master
origin/master
origin/share/branch1
origin/share/branch2
origin/share/another-branch
Can I do:
git merge origin/share/*
to merge with branch1, branch2 and another-branch?
I don't think you can use wildcards directly in that way, but you could use git for-each-ref
to match branch names. For example, look at the output of:
git for-each-ref --format="%(refname)" refs/remotes/origin/share/*bran*
(That's deliberately more than you need in the pattern, so that I could demonstrate that wildcards work. You could just do refs/remotes/origin/share/
instead.)
So, as one command you could do:
git merge $(git for-each-ref --format="%(refname)" refs/remotes/origin/share/)
... to do an octopus merge from all of those branches.
To be honest, though, I'm finding it hard to think of a situation where I wouldn't much prefer to do:
git merge origin/share/branch1
git merge origin/share/branch2
git merge origin/share/another-branch
... or perhaps if there are lots of branches:
for c in $(git for-each-ref --format="%(refname)" refs/remotes/origin/share/)
do
git merge $c || break
done
git branch -r | grep "share" | xargs git merge
?
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