Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding a git remote from "fetch --all"

Tags:

git

git-remote

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)

like image 876
Luciano Avatar asked Sep 03 '25 17:09

Luciano


2 Answers

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.

like image 175
Luciano Avatar answered Sep 07 '25 01:09

Luciano


Not really, no: --all means all. But you can define remote groups, and use git remote update to update the groups. Put the normally-unavailable remote into a group that's not the default group. See the git remote documentation for details.

(git fetch also works with groups, I just prefer to use git remote when dealing with groups and git fetch for one individual remote, myself. Probably a holdover from a decade-plus ago...)

like image 45
torek Avatar answered Sep 07 '25 00:09

torek