git clone writes to sderr, fine but why can't I redirect to stdout
Asked Answered
H

2

13

I figured that git clone uses STDERR.

I now want to redirect it to STDOUT to use this hack.

I'm having some issues (also, I use great stderred library to color STDERR red automatically).

You can see the problems in the attached image, doesn't make much sense to me... please clarify why this is happening and how to get all output to STDERR so I can use tee properly.

enter image description here

Hartzell answered 21/9, 2015 at 0:1 Comment(1)
Possible duplicate of git stderr output can't pipeLarimore
M
14

Like many Unix utilities, git-clone will be quieter if it's redirected to a pipe. The assumption is the output is useful to a human and it will just get in the way of a program. tee breaks this assumption, but git can't know what's at the end of the pipe.

From the git-clone manual...

--progress

Progress status is reported on the standard error stream by default when it is attached to a terminal, unless -q is specified. This flag forces progress status even if the standard error stream is not directed to a terminal.

You have to specify git clone --progress to force it to do the full output.

Malatya answered 21/9, 2015 at 0:14 Comment(3)
Thank you... I fixed this use case but later I noticed that git push also writes to STDERR and also wget etc.. what is the purpose then, don't get it... I have installed stderred and now too many outputs are red :/Hartzell
@DavidKrmpotic Those utilities are using STDERR and STDOUT to separate the content a human is interested in (progress) from what a program is interested in (did it work, what got transferred...). They have to make some assumptions. That stderrd looks cool. You can black list git and wget if you like with STDERRED_BLACKLIST. OR make normal text green and enjoy your Christmas themed terminal!Malatya
I didn't notice the BLACKLIST option.... but anyway, too much hassle, I stopped using stderrd not enough benefits, just complications with having to blacklist a lot of tools... thank you for your help on the main question again, really helpedHartzell
N
1

Here's a working example of redirecting stderr to stdout. My most recent use case is fixing a Github Actions bug that puts all stderr output at the top of the log, rather than putting it in sequence with stdout. When Microsoft fixes this bug I'll have a lot of unfixing to do on my end...

Proof of git clone using stderr:

$ (git clone --progress https://github.com/sindresorhus/ora.git 2>&1 | tee true) > cmd.stdout 2> cmd.stderr
$ cat cmd.stderr # Nothing here...
$ cat cmd.stdout
Cloning into 'ora'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 563 (delta 3), reused 7 (delta 2), pack-reused 551
Receiving objects: 100% (563/563), 652.32 KiB | 2.70 MiB/s, done.
Resolving deltas: 100% (346/346), done.

Kicking that stderr stream into stdout:

$ (git clone --progress https://github.com/sindresorhus/ora.git 2>&1 | tee true) > cmd.stdout 2> cmd.stderr
$ cat cmd.stderr # Nothing here now...
$ cat cmd.stdout
Cloning into 'ora'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 563 (delta 3), reused 7 (delta 2), pack-reused 551
Receiving objects: 100% (563/563), 652.32 KiB | 2.70 MiB/s, done.
Resolving deltas: 100% (346/346), done.
Noreennorene answered 19/2, 2021 at 6:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.