Skip to content
文章目录

git-url带账号和密码

url 格式

https://<user>:<password>@<gitserver>/<path>/<repo>.git

密码中的特殊字符转义

如果密码是纯文本,则可以正常工作,但如果密码具有感叹号等特殊字符,则需要使用 URL 编码。

!: %21
#: %23
$: %24
&: %26
’: %27
(: %28
): %29
*: %2A
+: %2B
,: %2C
/: %2F
:: %3A
;: %3B
=: %3D
?: %3F
@: %40
[: %5B
]: %5D

git remote add 带账号和密码

git remote add origin https://myuser:password%21@github.com/myuser/repo.git

git remote set-url 带账号和密码

git remote set-url origin https://myuser:password%21@github.com/myuser/repo.git

git clone url 带账号和密码

如果使用用户名+密码的方式来 clone 远程仓库,如下形式:

shell
git clone https://<user>:<password>@<gitserver>/<path>/<repo>.git

使用凭据 myuser/password! 到 github 存储库将如下所示:

shell
git clone https://myuser:password%21@github.com/myuser/repo.git

查看远程仓库的 url

shell
git remote -v

参考资料

GIT:使用带有特殊字符的密码调用 git clone

Git 远程推送时设置用户名和密码