Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
We have a multi-server Jenkins set up, which annoyingly sits waiting for a prompt until killed if it runs on a new server missing the ssh keys - a way to configure that it will simply fail with a message and non-zero exit code would be useful. –  Danny Staple Dec 2 '13 at 14:46
    
If a catch all "batch" mode could be used to disallow prompting for host keys too - this would be ideal. –  Danny Staple Dec 2 '13 at 14:55
    
These are both related - trying to piece them together - serverfault.com/questions/61915/…, stackoverflow.com/questions/7772190/…. –  Danny Staple Dec 2 '13 at 15:06

2 Answers 2

Depending on how you're running git, redirecting stdin or stdout so that they are not connected to terminals will stop git from prompting for details and just cause it to error.

This would also allow you to surface errors (or at least logs) to the webservice.

share|improve this answer
    
How exactly would I go about doing this? Trying to accomplish this in Bash first, both </dev/null and nohup .. & don't seem to work. –  Tin Tvrtković Oct 15 '13 at 21:56

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.