How can I make `git fetch --all` fail/show me failures prominently, if any of the remotes fail?

Viewed 75

My issue is that I have multiple remotes set up, but day to day I only push to one. Let's call this remote 'Frank'. The other one, I almost never pull from, lets call her 'Alex'.

The 'Alex' remote is reliable, 'Frank' is unreliable. He gives me:

fatal: Could not read from remote repository

When I run git fetch --all -p, if 'Frank' fails the error output gets crowded out and pushed off screen by the successful fetching of all the branches updated on 'Alex'. The issue comes, in that if I don't see that 'Frank' has failed again, I carry on gitting as though I'm up to date.

Can I make git --all fail if any of the remotes fail, with an extra option? The Git Fetch Docs give the --atomic option, but that says:

--atomic
Use an atomic transaction to update local refs. Either all refs are updated, or on error, no refs are updated.

Now I'm not certain that would work (does a remote not being reachable tell git that a local ref failed?), but I'm being told that atomic is not an options, and it's not listed in the usage output. I don't and can't get my git updated currently (I'm on v2.20.1).

Is that possible, or maybe something that suppresses anything not from 'Frank' ?

1 Answers

Add -q (or --quiet) to silence the success messages.
Then you're left with only error messages (if any).

git fetch --all -pq

Also the exit code will let you know whether or not there were errors.
You can use that to execute commands accordingly:

git fetch --all -pq && echo 'success' || echo 'FAILURE'

E.g. you could first run a dry-run before running a real fetch:

git fetch --dry-run --all -pq && git fetch --all -p

(However, if a remote is reachable during the dry-run, but not during the real fetch, then you won't get the desired result)

If you want to see errors AND remote branch updates (bash syntax):

git fetch --all -p |& grep -Ei '^( |error:|fatal:)'

If you only want to see errors and branch updates of remote "Frank" (bash syntax):

git fetch --all -p |& grep -Ei '^(error:|fatal:)|\bFrank/'
Related