Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force Git NOT to prompt for credentials

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.

like image 633
vaab Avatar asked May 09 '14 11:05

vaab


People also ask

How do I stop Git from asking for credentials?

You can avoid being prompted for your password by configuring Git to cache your credentials for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.

How do I stop git push from asking for username and password?

Issue the command git fetch/push/pull. You will not then be prompted for the password.

Why is git asking for username and password every time?

If Git is always asking you for your username and password when pushing or pulling your code from a GitHub repository, This is a common problem if you use HTTPS clone URL for cloning the repository. Let's see how to solve this! The https:// clone URLs are available on all public and private repositories.


1 Answers

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 ...
like image 53
vaab Avatar answered Oct 05 '22 08:10

vaab