在 Git 中存储用户名和密码

Gyp*_*aut 41 git

当我做

git push
Run Code Online (Sandbox Code Playgroud)

我得到命令提示符

Username for 'https://github.com':
Run Code Online (Sandbox Code Playgroud)

然后我手动输入我的用户名

Username for 'https://github.com': myusername
Run Code Online (Sandbox Code Playgroud)

然后我点击Enter并提示我输入密码

Password for 'https://myusername@github.com':
Run Code Online (Sandbox Code Playgroud)

我希望用户名自动写入,而不是一直手动输入。

我尝试这样做,xdotool但没有成功。

我已经做了

git config --global user.name myusername
git config --global user.email myemail@gmail.com
Run Code Online (Sandbox Code Playgroud)

但它仍然总是要求我手动输入

pro*_*sti 46

在终端中,输入以下内容以启用凭证记忆:

$ git config --global credential.helper cache
Run Code Online (Sandbox Code Playgroud)

您可以更新默认密码缓存超时(以秒为单位):

# This cache timeout is in seconds
$ git config --global credential.helper 'cache --timeout=3600' 
Run Code Online (Sandbox Code Playgroud)

您也可以使用(但请使用引号,否则双引号可能会中断某些字符):

$ git config --global user.name 'your user name'
$ git config --global user.password 'your password'
Run Code Online (Sandbox Code Playgroud)

  • 如何永久缓存? (3认同)
  • @R.Gurung 在这种情况下使用 `git config credential.helper 'store`,但要注意_这会将您的 `git` 凭据以纯文本形式存储在磁盘上,没有任何加密。(`~/.git-credentials`) (3认同)
  • 注意,上面的代码片段也应该被 --global 标记,并关闭它的开头 ''`,这样它就会显示: 'git config --global credential.helper 'store'` (3认同)

Die*_*cia 17

实际上,您在那里所做的是设置作者信息,仅用于提交。您没有存储凭据。凭证可以通过两种方式存储:

  1. 使用 git 凭证功能:https : //git-scm.com/docs/git-credential-store
  2. 将原始 url 更改为“ https://username:password@github.com ”。
  3. 第三种选择是使用 ssh 密钥(如@StephenKitt 所说)。对于 github 配置,您可以在 GitHub 帮助页面中找到所有需要的信息


小智 7

git scm复制这个

$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
[several days later]
$ git push http://example.com/repo.git
Run Code Online (Sandbox Code Playgroud)

[您的凭据将自动使用]