gitgit-refspec

Ignore a single namespace in git refspec


Consider the following repository. It has a lot of private branches for team members, all under the refs/heads/team/ namespace, that I do not want to fetch, but I still do want to fetch all the rest, including any possibly newly created branches outside of that team namespace.

$ git ls-remote http://gerrit.asterisk.org/asterisk refs/heads/* | wc -l
217
$ git ls-remote http://gerrit.asterisk.org/asterisk refs/heads/* | grep -v refs/heads/team/ | wc -l
32

I am fetching fetch = +refs/heads/*:refs/remotes/golden/*, but these private branches are just overwhelming my refs/remote/golden namespace, making it harder to overview, and also require more space for the local repository.

Is it possible to fetch refs/heads/*, but exclude refs/heads/team/* ?


Solution

  • Duplicate: Skip copying some branches/tags to local Git with git fetch --all

    This is supported since Git 2.29:

    Assuming your remote is named origin, you should be able to use git config --add remote.origin.fetch '^refs/heads/team/*' to exclude the refs/heads/team/ prefix from fetches.