gpt4 book ai didi

git - 多账号命令行登录GitHub

转载 作者:太空狗 更新时间:2023-10-29 13:49:28 24 4
gpt4 key购买 nike

我开设了一个新的 GitHub 帐户,以将我的业务存储库与个人存储库分开。

现在,我 git init我的本地存储库和 git add remote origin <the repository HTTPS URL>

我尝试推送,它似乎总是使用我的原始帐户的凭据,而不是提示我输入新帐户的凭据。

我尝试使用 URL 格式

https://<username>:<password>@github.com/<username>/<repository.git>

但这似乎无济于事:我仍然收到错误消息,指出凭据对于原始帐户用户名无效。

我如何使用多组凭据登录,或者我如何以某种方式重置原始凭据以在推送时强制提示密码?


我现在设法推送的唯一方法是指定 username:password@github.com/在 URL 中 git push命令。

最佳答案

git config --global credential.helper cache

... 这告诉 git 将您的密码在内存中缓存(默认情况下)15 分钟。你可以set a longer timeout与:

git config --global credential.helper "cache --timeout=3600"

更有用的链接:

https://confluence.atlassian.com/bitbucketserver/permanently-authenticating-with-git-repositories-776639846.html

Using the .netrc file The .netrc file is a mechanism that allows you to specify which credentials to use for which server.

This method allows you to avoid entering a username and password every time you push to or pull from Git, but your Git password is stored in plain text.


您可以使用以下命令存储您的凭据

git config credential.helper store
git push http://example.com/repo.git
# Now type username and password and it should be saved by git.

关于git - 多账号命令行登录GitHub,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34731832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com