Search code examples
gitgit-remote

Excluding a git remote from "fetch --all"


Is it possible to have configured remotes in git that are only fetched when formally requested by its name? So they would be excluded of operations like fetch --all.

Imagine a dormant (disabled, or something) remote called "my-no-auto-fetch-remote":

$ git fetch my-no-auto-fetch-remote

(it's fetched)

$ git fetch --all

(the my-no-auto-fetch-remote shouldn't be fetched)


Solution

  • There is a configuration skipFetchAll for remotes.

    From the documentation on: https://git-scm.com/docs/git-config/1.9.2

    remote..skipFetchAll

    If true, this remote will be skipped by default when updating using git-fetch[1] or the update subcommand of git-remote[1].

    As there is no option at command line when adding or changing a remote, I had to put that configuration editing the .git/config file, as:

    [remote "my-remote"]
            url = git@the-repository-url
            fetch = +refs/heads/*:refs/remotes/my-remote/*
            skipFetchAll = true
    

    You can add this from the command-line using

    git config remote.my-remote.skipFetchAll true
    

    where my-remote is the remote name that should be excluded from git fetch --all.