本文介绍了如何输入密码给git pull命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经为Windows和Linux编写脚本,从本质上设置了一个新的用户工作区,其中包含来自服务器的所有git存储库。
我希望用户输入我们的服务器的密码一次,将其存储在本地变量中,将该变量传递给每个 git pull
命令,然后擦除密码变量并退出。
当 git pull
命令请求它时,我怎样才能输入密码?对于Windows批处理文件和Linux shell脚本。
以下是Linux脚本中的代码:
<$ p $ #!/ bin / bash
echoEnter password:
read pswd
clear #No screen peaking
#对于每个回购重复
位置=文件夹名称
mkdir $位置
cd位置
git init
git remote add origin git @< server> ;: $ location.git
git pull origin master
#Above提示输入密码&是我想要自动输入$ pswd
的地方我已经尝试过在SO和其他地方推荐的各种东西,如管道,从.txt文件中读取数据等。我宁愿不需要比普通的旧式Windows cmd和Linux终端命令更多的东西。因为这个脚本只是为了设置目的,所以我不需要像ssh代理那样永久安全地存储密码。
我运行Windows 7和Ubuntu 12.10,但是这个脚本是为了设置新用户而设计的,所以它应该适用于大多数发行版。
建议不要尝试并管理该密码步骤,并将其(在Linux和Windows上)( git凭证助手)委托给其他人。<
请参阅
用户每次只会输入一次密码。
I have written scripts for Windows and Linux to essentially set up a new users workspace with all the git repositories from our server.
I would like the user to enter the password for our server once, store it in a local variable, pass that variable to each git pull
command, then erase the password variable and exit.
How can I input the password when the git pull
command requests it? Both for Windows batch file and a Linux shell script.
Here is code from the Linux script:
#!/bin/bash
echo "Enter password: "
read pswd
clear #No screen peaking
#This is repeated for each repo
location=folderName
mkdir $location
cd $location
git init
git remote add origin git@<server>:$location.git
git pull origin master
#Above prompts for password & is where I want to automatically input $pswd
I've tried various things recommended on SO and elsewhere, such as piping, reading from .txt file, etc. I would prefer to not need anything more than plain old windows cmd and Linux terminal commands. And as this script is just for set up purposes, I do not need to securely store the password permanently with something like ssh agent.
I'm running Windows 7 and Ubuntu 12.10, but this script is meant for setting up new users, so it should ideally work on most distributions.
解决方案
I would really recommend to not try and manage that password step, and delegate that (both on Linux and Windows) to git credential helper.
See:
The user will enter the password only once per session.
这篇关于如何输入密码给git pull命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!