Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcards in branch names specification in "git merge"

Tags:

git

merge

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?

like image 408
sbos Avatar asked Dec 16 '22 16:12

sbos


2 Answers

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
like image 74
Mark Longair Avatar answered Dec 19 '22 06:12

Mark Longair


git branch -r | grep "share" | xargs git merge ?

like image 33
here Avatar answered Dec 19 '22 07:12

here