Wildcards in the specification of branch names in "git merge"

Is it possible to use wildcards in some way 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 

Is it possible:

 git merge origin/share/* 

to merge with branch1, branch2, and another branch?

+4
source share
2 answers

I don't think you can use wildcards directly that way, but you can use git for-each-ref to match branch names. For example, look at the output:

 git for-each-ref --format="%(refname)" refs/remotes/origin/share/*bran* 

(This is intentionally larger than what is needed in the template so I can demonstrate that wildcards work. Instead, you can do refs/remotes/origin/share/ .)

So, as one command, you can do:

 git merge $(git for-each-ref --format="%(refname)" refs/remotes/origin/share/) 

... to make an octopus axis from all of these branches.

To be honest, it's hard for me to think about a situation in which I would not prefer to do anymore:

 git merge origin/share/branch1 git merge origin/share/branch2 git merge origin/share/another-branch 

... or perhaps if there are many branches:

 for c in $(git for-each-ref --format="%(refname)" refs/remotes/origin/share/) do git merge $c || break done 
+9
source

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

+2
source

Source: https://habr.com/ru/post/1342405/


All Articles