如何强制Git不提示输入凭据 [英] How do I force Git NOT to prompt for credentials

查看:73
本文介绍了如何强制Git不提示输入凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Bash脚本中使用 git clone ,该脚本具有任何类型的Git位置(HTTPS,Git,SSH,文件系统...),并将对其进行克隆.但是该脚本必须能够在不与任何用户交互的情况下工作.更准确地说,我希望此脚本不暂停获取凭据:如果该位置需要凭据,而git无法自行找到它们,则我希望Git失败.

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).

因此,在我当前的担忧中,我要求 git clone 失败,而不是询问凭据.

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

我没有在 git clone 中找到任何选项来强制不要求提供凭据,并且最好在身份验证错误时失败.

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

推荐答案

更新: in git version> 2.3 :

UPDATE: in git version > 2.3:

GIT_TERMINAL_PROMPT=0 

对于以前的版本:

这是我强迫失败的把戏:

Here's my trick to force failing:

GIT_ASKPASS=/bin/echo git clone ...

这篇关于如何强制Git不提示输入凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆