Reputation: 13863
I am working on an application where a user can enter a Git repository, which is then cloned to the local machine. In some cases (such as a mistyped URL pointing to a nonexistent repo on Github), the Git client will prompt the user for a username and password. I do not want this behavior -- I just want Git to fail with a non-zero error status. A non-interactive error message is OK, I just to avoid the password prompt causing my application to hang.
How can I achieve this?
Upvotes: 6
Views: 1505
Reputation: 3014
In addition to GIT_TERMINAL_PROMPT=0
, the following helps to also suppress credential manager windows
git -c credential.helper= <rest of commands>
Upvotes: 1
Reputation: 11424
You can set the GIT_TERMINAL_PROMPT
environment variable to 0
if you don't want git to prompt for any input.
>>> git clone https://github.com/private/private.git
Cloning into 'private'...
Username for 'https://github.com':
>>> GIT_TERMINAL_PROMPT=0 git clone https://github.com/private/private.git
Cloning into 'private'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Alternatively, can set the GIT_ASKPASS
environment variable or core.askpass
configuration value to true
(or a blank script).
>>> git clone https://github.com/private/private.git
Cloning into 'private'...
Username for 'https://github.com':
>>> GIT_ASKPASS=true git clone https://github.com/private/private.git
Cloning into 'private'...
remote: Repository not found.
fatal: Authentication failed for 'https://github.com/private/private.git/'
Both solutions have non-zero exit codes.
Upvotes: 11