'git config: remote.<name>.fetch - is it possible to set up exceptions?

It is possible to set up rules like fetch = +refs/heads/*:refs/remotes/origin/* to fetch all branches matching certain glob.

But is it possible to exclude something from the list? For example, I don't want to fetch anything from refs/heads/X/* because it is used by our automated tool, and there're often lots of small branches I have no need to see ever.

git


Solution 1:[1]

Starting with Git v2.29.0, there is a way. Negative refspecs have been added to the logic.

Add another line to your .git/config for that remote that looks like this: fetch = ^refs/heads/X/*. You can find more details in this other answer.

Solution 2:[2]

Unfortunately, no. To exclude X/* you must list (positively) everything not X/*.

Depending on how you name your refs / branches, this may be easy enough, or may be especially difficult. You could automate it to a large extent using git ls-remote and a script (use grep, or python code, or whatever, to exclude X/* while adding every other reference).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 torek