Question

I'm using git clone in a Bash script that takes any type of Git location (HTTPS, Git, SSH, filesystem...) and will clone it. But this script must work without interaction with any user. More precisely, I would like this script to NOT PAUSE for credentials: if the location requires credentials, and git can't find them on its own, I want Git to fail.

My script makes the assumption that it's not its concerns if you didn't setup proper way to access to these locations without password. However, the solution should let a way to know what the failure was (outputting an error with "Authentication Failed" for example).

I need this behavior simply because it's a script, it is to be run non-interactively (cron job, VM building ... etc ...). I need it to fail and not freeze my script waiting for information that I can't feed it (and don't wan't to).

So, in my current concern, I require that git clone fails instead of asking about credentials.

I didn't find any option in git clone to force NOT to ask for credential and preferably fail on an authentication error.

Was it helpful?

Solution

UPDATE: in git version > 2.3:

GIT_TERMINAL_PROMPT=0 

For previous version:

Here's my trick to force failing:

GIT_ASKPASS=/bin/echo git clone ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top