使用密码进行Git克隆

12

我需要转义密码中的@符号,因为它容易被误认为是主机名。

示例1: git clone https://user:p%40ssword@github.com/user/repo.git

当我运行上面这个示例时会出错,因为密码里有@符号,系统会将其解释成主机名。我尝试用 \ 转义或者把url放在 "" 里但都不起作用。

示例2: (echo user; echo p@ssword) | git clone https://github.com/usuario/repo.git

当我只使用 git clone https://github.com/usuario/repo.git 命令时,会要求输入用户名和密码,所以我使用了上面这个命令,在一行中完成更改根密码的操作。

3个回答

13

完美的 %40 谢谢 - Gustavo Filgueiras

5

您可以将@替换为其URL编码格式%40

如果您的密码是password@99,请将其更改为password%4099

git clone https://username:password%4099@bitbucket.org/sarat.git

1

请检查链接 Git配置

在本地配置您的git账户 -

git config --global user.name myName

git config --global user.email myEmail

以下命令将在一段时间内将您的密码保存在内存中。

$ git config --global credential.helper cache

设置git使用凭据内存缓存

$ git config --global credential.helper 'cache --timeout=3600'

将缓存设置为1小时后超时(设置以秒为单位)

希望这能帮到您


这并不表示如何转义字符。 - Itération 122442

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接