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.
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.
Issue the command git fetch/push/pull. You will not then be prompted for the password.
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.
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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With