Search code examples
gitpushstdin

Redirect 'terminal' to 'stdin' when pushing using git


Is there any way to redirect terminal input to stdin when pushing as below?

$ git push origin master
Username for 'https://github.com':

Then I can pass my username/password through stdin.

For example, in linux based systems, the sudo command always read the password from terminal but if you provide it with a -S flag then it will read the password from stdin.

I'm just curious if there is any similar flag in git command?

NOTE: My question is just about redirecting input of git command to stdin and I don't care about security or any other thing.


Solution

  • Git generally doesn't do its own password-asking: it fobs that job off on other programs.

    When using ssh (git clone ssh://... etc.), Git just runs ssh itself directly. That leaves everything up to ssh.

    When using http or https, Git uses the libcurl library and credential helpers. You can tell Git which credential helper to use, so you could write one yourself that reads a password from standard input, and tell Git to use that one. This would be rather insecure, but you could definitely do it.

    For the rest, see Git push requires username and password.