Why does git still print to the screen when both stdout and stderr have been redirected?

Viewed 109

I want to mute the output of a git push command used in my CI system which may leak sensitive information.

The command is:

git --quiet push > /dev/null 2>&1

so it should not print anything to the screen. But it still prints Password for 'https://xxxx@github.com': when auth fails.

How could this happen and how to mute it?

Update: Though I am not sure, I guess git calls getpass() or something similar that writes to /dev/tty directly.

2 Answers

To prevent key logging and work around redirects password prompt is done via /dev/tty. See how this is done in Python's getpass.

Git explicitly opens /dev/tty for reading and writing, which is used for the password prompt.

/dev/tty was added to Unix at around 1979, allowing programs to obtain a file descriptor to the controlling terminal, so user input was made possible when stdin is occupied, as well as when both stdout and stderr are redirected.

See How does less take data from stdin while still be able to read commands from user?

Related