在python / shell中输入git和hg的密码/名称

时间:2014-02-18 11:28:42

标签: python git shell github mercurial

我想从python / shell脚本输入git的名称和密码以及github的密码

但是:

echo mypasswd | hg push

作为:

echo myname mypasswd | git push origin master

不起作用

3 个答案:

答案 0 :(得分:2)

您可以使用:

git pull https://[user]:[passwd]github.com/[account]/[repo].git [branch]

或者将其添加为遥控器:

git remote add origin https://[user]:[passwd]@github.com/[account]/[repo].git

如果您想保留新遥控器的名称origin,则应首先使用git remote remove origin

删除旧遥控器

答案 1 :(得分:1)

通常,当您想要提供交互式命令的答案时,您可以使用以下内容进行操作:

myCommand <<EOF  
some answer  
some other answer  
EOF

但我担心你不能使用这种重定向/管道来为你的命令提供密码。正如@Fidel指出的那样,您应该检查expect命令。

此外,您应该使用rsa密钥在SCM上进行身份验证;)

答案 2 :(得分:1)

对于Mercurial,您应该看看如何store HTTPS credentials。有几种选择:您可以将密码存储在config file中,您可以使用keyring extension,也可以将其硬编码到网址中:

hg pull https://username:password@host/repo

如果您在受信任的计算机上,则只将密码放入网址 - 登录计算机的其他人将能够在hg pull正在运行时看到密码。