{"thread":{"id":"61865","subject":"Output of git checkout goes to stderr","startedAt":"2024-07-30T05:44:31Z","lastAt":"2024-07-30T15:45:42Z","messageCount":4,"participants":["Sayooj Surendran","Eric Sunshine","Karthik Nayak","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"499561","messageId":"CAFGW38fkr+OuhpcyqNFxZNkhNDGPxTbOmCJLVHpCGUmbj05tMg@mail.gmail.com","threadId":"61865","inReplyTo":null,"subject":"Output of git checkout goes to stderr","fromName":"Sayooj Surendran","fromEmail":"sayooj.surendran@bigbinary.com","sentAt":"2024-07-30T05:44:18Z","receivedAt":"2024-07-30T05:44:31Z","isPatch":false,"sender":{"key":"sayooj.surendran@bigbinary.com","avatar":null},"body":"Hi,\nNoticed that the output of git checkout command is going to stderr\nchannel. Is this an intended behaviour?\ngit version: 2.45.2\nterminal output:\n\n❯ git checkout -b test > stdout.txt 2> stderr.txt\n❯ cat stdout.txt\n❯ cat stderr.txt\nSwitched to a new branch 'test'\n"},{"id":"499576","messageId":"CAPig+cTGhzZom+27WEHFbij-_MdFL+tNQ0uQZ3wskB1v10fHVg@mail.gmail.com","threadId":"61865","inReplyTo":"CAFGW38fkr+OuhpcyqNFxZNkhNDGPxTbOmCJLVHpCGUmbj05tMg@mail.gmail.com","subject":"Re: Output of git checkout goes to stderr","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2024-07-30T07:36:30Z","receivedAt":"2024-07-30T07:36:42Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Jul 30, 2024 at 1:44 AM Sayooj Surendran\n<sayooj.surendran@bigbinary.com> wrote:\n> Noticed that the output of git checkout command is going to stderr\n> channel. Is this an intended behaviour?\n\nYes, it is intentional. Git's Documentation/CodingGuidelines has this to say:\n\n--- >8 ---\nProgram Output\n\n We make a distinction between a Git command's primary output and\n output which is merely chatty feedback (for instance, status\n messages, running transcript, or progress display), as well as error\n messages. Roughly speaking, a Git command's primary output is that\n which one might want to capture to a file or send down a pipe; its\n chatty output should not interfere with these use-cases.\n\n As such, primary output should be sent to the standard output stream\n (stdout), and chatty output should be sent to the standard error\n stream (stderr). Examples of commands which produce primary output\n include `git log`, `git show`, and `git branch --list` which generate\n output on the stdout stream.\n\n Not all Git commands have primary output; this is often true of\n commands whose main function is to perform an action. Some action\n commands are silent, whereas others are chatty. An example of a\n chatty action commands is `git clone` with its \"Cloning into\n '<path>'...\" and \"Checking connectivity...\" status messages which it\n sends to the stderr stream.\n\n Error messages from Git commands should always be sent to the stderr\n stream.\n--- >8 ---\n"},{"id":"499578","messageId":"CAOLa=ZRQ2YA=AAUQE9R6K-+o3MGZ8RmcckNi2-txKONC94ceRA@mail.gmail.com","threadId":"61865","inReplyTo":"CAFGW38fkr+OuhpcyqNFxZNkhNDGPxTbOmCJLVHpCGUmbj05tMg@mail.gmail.com","subject":"Re: Output of git checkout goes to stderr","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-07-30T07:46:33Z","receivedAt":"2024-07-30T07:46:35Z","isPatch":false,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Sayooj Surendran <sayooj.surendran@bigbinary.com> writes:\n\nHello,\n\n> Hi,\n> Noticed that the output of git checkout command is going to stderr\n> channel. Is this an intended behaviour?\n> git version: 2.45.2\n> terminal output:\n>\n> ❯ git checkout -b test > stdout.txt 2> stderr.txt\n> ❯ cat stdout.txt\n> ❯ cat stderr.txt\n> Switched to a new branch 'test'\n\nThanks for reporting, this seems to be as expected. Note that all\nchatty feedback is routed to stderr in Git.\n\nThis is also documented in 'Documentation/CodingGuidelines':\n\n  We make a distinction between a Git command's primary output and\n  output which is merely chatty feedback (for instance, status\n  messages, running transcript, or progress display), as well as error\n  messages. Roughly speaking, a Git command's primary output is that\n  which one might want to capture to a file or send down a pipe; its\n  chatty output should not interfere with these use-cases.\n\n  As such, primary output should be sent to the standard output stream\n  (stdout), and chatty output should be sent to the standard error\n  stream (stderr). Examples of commands which produce primary output\n  include `git log`, `git show`, and `git branch --list` which generate\n  output on the stdout stream.\n\nThanks,\nKarthik\n"},{"id":"499619","messageId":"xmqqed7ag9y7.fsf@gitster.g","threadId":"61865","inReplyTo":"CAFGW38fkr+OuhpcyqNFxZNkhNDGPxTbOmCJLVHpCGUmbj05tMg@mail.gmail.com","subject":"Re: Output of git checkout goes to stderr","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-30T15:45:36Z","receivedAt":"2024-07-30T15:45:42Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sayooj Surendran <sayooj.surendran@bigbinary.com> writes:\n\n> Noticed that the output of git checkout command is going to stderr\n> channel. Is this an intended behaviour?\n\nShow messages meant for human consumptions (not just errors and\nwarnings, but informational messages and eye-candy progress bars) to\nthe standard error stream, and using the standard output stream to\nshow what informational commands are asked to produce (e.g. running\n\"git status\" would describe the status of the current working tree\nto the standard output stream), is very much in line with the\noriginal design we laid out in 2005 when Git was still very young,\nand continues to be \"intended\" behaviour to this day.\n"}]}