用于git push的命令中的用户名和密码

Jak*_*ake 85 git git-bash

可以克隆一个git存储库,在命令中指定用户名和密码.例:

git clone https://username:password@myrepository.biz/file.git

是否可以在推送时指定用户名和密码?因此,例如,运行git push origin --all将输出要求输入密码.我希望在一个命令中.

(我知道设置密钥和其他解决方案的能力,但我想知道是否有办法只使用一个命令继续使用用户名和密码.)我在Windows 8.1上运行Git Bash.

num*_*er5 131

是的,你可以做到

git push https://username:password@myrepository.biz/file.git --all

在这种情况下,https://username:password@myrepository.biz/file.git替换originingit push origin --all

要查看更多选项git push,请尝试git help push

  • 请注意,这将在git配置中以明文*存储用户名和密码*. (13认同)
  • 如果密码包含`@`会发生什么? (12认同)
  • 而不是普通密码,您可以使用密码哈希 (4认同)
  • 建议用`' '把完整路径括起来,例如:`git push 'https://username:password@myrepository.biz/file.git'` (3认同)
  • @VasiliyVanchuk 你使用什么样的哈希?这对 Github 有用吗? (2认同)

小智 15

我使用以下格式

git push https://username:password@myrepository.biz/file.git --all

如果您的密码或用户名包含@,请用%40替换


Chr*_*ams 15

对于任何有特殊字符密码问题的人,只需省略密码,它会提示您输入:

git push https://YOUR_GIT_USERNAME@github.com/YOUR_GIT_USERNAME/yourGitFileName.git
Run Code Online (Sandbox Code Playgroud)

  • 似乎您的答案是整个网络上唯一直接说明如何仅提供用户名的答案。 (3认同)

Moh*_*taz 12

2021 年 8 月 13 日删除了对密码身份验证的支持。您可以改用个人访问令牌。就像下面的推送命令:

git push https://<User Name>:<Token>@github.com/<User Name>/<Your Repository>.git
Run Code Online (Sandbox Code Playgroud)

链接到如何创建访问令牌