Question: When cloning git repositories in automated tools - web front ends, CI systems, sometimes the git clone invocation opens up a prompt asking for the username and password (for example, when cloning a non-existent Github repo or on a new node missing ssh keys).

How do I make git just fail (preferably with a sensible error message and exit code) instead of waiting for the server process to give it a username and password?

Answer: 
If you are using ssh authentication, and on linux, then you can create an ssh command replacement to disable this.

Create a file called "sshnoprompt.sh" with:

`ssh -oBatchMode=yes $@`

Make this file executable with `chmod +x sshnoprompt.sh`

Then when starting git:

`GIT_SSH="sshnoprompt.sh" git clone foo@dummyserver:not_a_repo`

And it will not allow any interactive git prompts or questions - it shouldn't be able to ask the user for anything.
Working from git version 1.8.3.1;

`git clone -c core.askPass $echo url/or/path/to/git/repo`

The configuration [`core.askPass`](https://git-scm.com/docs/gitcredentials) works by passing the control of handling credentials to the aforementioned program. However since `$echo` cant do anything except output, the clone attempt promptly fails and respective bash redirection applies. This code is only invoked in the event that the git repository happens to be private, and will pipe error output stating that authentication failed for the particular repository. You can test this against the `https://github.com/git/git` public repository against a private repository you know about. 

To sweeten the deal, you wouldn't even need to reference a program like `echo` in the first place. Simply passing git configuration `-c core.askPass` with no following input would still cause failure in the event the repository happens to be private as the code will not know what program to offload credential handling to. While this is certainly an older and simpler method than the others mentioned here, I do not know if it will have the same effect in older versions of git.