如何input密码给git pull命令?

我已经为Windows和Linux编写脚本,从本质上设置了一个新的用户工作区,其中包含我们服务器上的所有git存储库。

我希望用户input一次服务器的密码,将其存储在本地variables中,将该variables传递给每个git pull命令,然后清除密码variables并退出。

git pull命令请求时如何input密码? 用于Windowsbatch file和Linux shell脚本。

这是来自Linux脚本的代码:

 #!/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 

我已经尝试了各种build议SO和其他地方的东西,如pipe道,从.txt文件中读取等,我宁愿不需要比普通的旧的Windows CMD和Linuxterminal命令更多的东西。 由于这个脚本只是为了设置目的,我不需要像ssh代理一样永久地存储密码。

我正在运行Windows 7和Ubuntu 12.10,但是这个脚本是为了设置新用户,所以它应该适用于大多数发行版。

我真的建议不要尝试和管理密码步骤,并委托(在Linux和Windows) git凭证助手
看到:

  • “ Git的http – 安全地记住凭据 ”
  • “ 如何使用git与gnome-keyring集成 ”

用户每次只会输入一次密码。

概要:

 git pull "https://<username>:<password>@github.com/<github_account>/<repository_name>.git" <branch_name> 

例:

 git pull "https://admin:12345@github.com/Jet/myProject.git" master 

注意:这对我来说是一个bash脚本