git - 提供带有密码的 git URL,包括 "@"符号

标签 git

我想用用户名和密码运行 git 命令(比方说 push 命令)。但是密码最后有一个@ sing。所以它给了我这个错误。

Couldn't resolve host '@github.com'

我的示例 git 命令是这样的。

git push https://username:password@@github.com/username/test.git

我认为密码的结尾@符号是错误的原因。但无论如何,我想找到一种方法来一步运行此命令,而无需在第二步输入用户名和密码。

最佳答案

来自 RFC 1738:

"...Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL."

因此您必须对 @ 字符进行 URL 编码:

git push https://username:password%40@github.com/username/test.git

但是,这不安全。不仅 URL 在 HTTP 流量中清晰可读,而且它们被主机缓存,被记录器记录,并被代理和路由器以多种方式存储在到达目的地的路径上。 如果密码无法提供身份验证,为什么还需要密码?如果您不需要身份验证,请不要使用密码。

此外,浏览器不赞成在 URL 中提供密码,例如阅读 http://support2.microsoft.com/default.aspx?scid=kb;[LN];834489

有几种更安全的方法可以执行一步推送而无需输入密码,例如使用 SSH key 或 git config credential.helper

关于git - 提供带有密码的 git URL,包括 "@"符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32714399/

相关文章:

git - 显示以前线路的变化

Git:裸存储库转换为工作:撤消此操作

git - 致命的 : bad config value for 'core.sharedrepository' in ./配置

windows - Git - 无法在 Windows 上推送到本地裸存储库

java - 在Eclipse(STS)中设置两个maven git项目的master分支

git - 有 .gitnotice 文件吗?

git - 永久继续之前提交的工作

git - 制作一个 shell 脚本来更新 3 个 git repos

windows - Windows 下使用 Git 的 SSH 失败

GitHub token - 限制访问