我开了一个新的GitHub帐户来分隔我的商业和个人回购.
现在,我是git init我当地的回购和git add remote origin <the repository HTTPS URL>
我尝试推送,它似乎总是采用我原始帐户的凭据,而不是提示我输入新帐户的凭据.
我尝试使用url格式
https://<username>:<password>@github.com/<username>/<repository.git>
Run Code Online (Sandbox Code Playgroud)
但这似乎没有帮助:我仍然收到一个错误,即凭据对原始帐户用户名无效.
如何使用多组凭据登录,或者如何在推送时以某种方式重置原始凭据以强制密码提示?
编辑:
我现在设法推动的唯一方法是在中指定username:password@github.com/urlgit push
小智 11
在您的 shell 中,添加您的用户名:git config --global user.name "your_username"
添加您的电子邮件地址:git config --global user.email "your_email_address@example.com"
要检查配置,请运行:git config --global --list
打开 bash 或终端。
cd ~/.ssh
ls
应该有这两个文件:id_rsa 和 id_rsa.pub。这些是登录凭据。
如果 id_rsa.pub 中的电子邮件与您要使用的电子邮件不匹配,请创建新凭据。为了简单起见,请使用“id_rsa”作为保存密钥的文件并创建一个密码以供以后保存
ssh-keygen -t rsa -C "your_email@example.com"
将您的密码保存在安全的地方,以便在推送时使用,否则您将需要再次执行此操作。
vim ~/.ssh/id_rsa.pub
复制 id_rsa.pub 的内容并将其粘贴到 GitHub网站的帐户设置 > SSH 和 GPG 密钥下。完全按照显示的样子复制所有内容,没有多余的空格或行。为这些凭据指定一个名称,以提醒您它来自哪台计算机。
再次尝试git Push
如果您收到有关权限过于开放的警告,Permissions 0644请尝试以下操作:
chmod 400 ~/.ssh/id_rsa~/.ssh/config指向正确的私钥git config --global credential.helper cache
Run Code Online (Sandbox Code Playgroud)
...告诉git将密码缓存在内存中(默认情况下)为15分钟.您可以设置更长的超时:
git config --global credential.helper "cache --timeout=3600"
Run Code Online (Sandbox Code Playgroud)
更有用的链接:
使用.netrc文件.netrc文件是一种允许您指定要用于哪个服务器的凭据的机制.
这种方法允许您在每次从Git推送或拔出时都避免输入用户名和密码,但您的Git密码以纯文本格式存储.
您可以使用以下命令存储凭据
git config credential.helper store
git push http://example.com/repo.git
# Now type username and password and it should be saved by git.
Run Code Online (Sandbox Code Playgroud)