Ignore remote refs with git

I am working on a project that uses github pages for publishing its documentation. One annoying thing with github-pages is, that it adds a new branch to your repository that is completely useless for you and you do not care at all on your local machine about that branch.

Very recently, this project also enabled dependabot. Dependabot is really nice, but what it does: It creates new branches in your repository where it files the pull requests from. That's obviously totally okay, but that results in more branches that happen to get downloaded every git-fetch that I do not really care about – after all I can see the pull request in the repository and handle them there!

So what do we do? Right! We use our git superpowers to simply ignore these remote refs!

Here comes the trick: You can teach git to ignore remote refs, and that even works with patterns! So what you do is, you go to the .git/config of the repository in question. You find the remote that you're concerned about and you add a new line to the configuration of that remote:

fetch = ^refs/heads/gh-pages

It is as easy as that!

To check whether everything worked, you can delete the remote ref of the github pages branch that you already fetched from your local repository via

git branch -r -d <remote>/gh-pages

And then check whether it gets re-fetched via simply git fetching from that remote.

To ignore by pattern, for example for dependabot branches, you can insert (on a new line of course)

fetch = ^refs/heads/dependabot/*

And delete the already fetched remote refs again via

git branch -r -d <remote>/dependabot/...

Piece of cake.