user3903517
user3903517

Reputation: 77

Output of git command is not fully redirected to a file

The output of git fetch command, is redirected to "test1" file from the below cmd:

manish@rigved:~$ git fetch --all --prune > test1
From https://github.com/Beawel/wwwnew
 x [deleted]         (none)     -> origin/test

Question: However the "x [deleted] ..." line as shown in the output is not redirected to test1, why? Please suggest.

Why a git command would print what is clearly not an error message on stderr?

manish@rigved:~$ cat test1
Fetching origin

Upvotes: 3

Views: 3715

Answers (1)

VonC
VonC

Reputation: 1323145

You need to redirect stderr in addition of stdout.

git fetch --all --prune > test1 2>&1

More importantly, why a git command does emit information on stderr instead of stdout?
That is specific to git (and not a duplicate of the well-documented stderr redirection).

As I explained here:

It is consistent with the rest of progress reporting within Git.
Reroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.

You would find on stdout git command outputs that could potentially by used by other commands in a chained-pipe sequence.
Any other message (not meant to be consumed by other commands) is redirected to stderr.

Upvotes: 6

Related Questions