3

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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
user3903517
  • 77
  • 2
  • 8
  • where is that *github command* you are referring to in the title? – umläute Jun 12 '16 at 07:14
  • I voted to reopen (http://stackoverflow.com/posts/37771591/timeline) because of the git specific aspect of this question, but I had no idea I could actually reopen directly with my only vote... apologies to moderators who closed this as duplicate of http://stackoverflow.com/q/637827/6309 or http://stackoverflow.com/q/7526971/6309: I meant no disrespect. – VonC Jun 12 '16 at 20:17

1 Answers1

5

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250