我从我的GitHub帐户克隆了一个Git存储库到我的电脑。

我想使用我的电脑和笔记本电脑,但只有一个GitHub帐户。

当我尝试使用我的电脑推送到GitHub或从GitHub中拉取时,它需要用户名和密码,但当我使用笔记本电脑时不需要!

我不想每次与origin交互时都键入用户名和密码。我在这里缺少什么?


当前回答

对我有用的是编辑.git/config并使用

[remote "origin"]
        url = https://<login>:<password>@gitlab.com(...).git

不用说,这是一种不安全的密码存储方式,但在某些环境/情况下,这可能不是问题。

其他回答

如果您克隆了HTTPS而不是SSH,并且在pull、push和fetch时遇到用户名和密码提示问题。您可以简单地为UBUNTU解决此问题

步骤1:移动到根目录

cd ~/

创建文件.git凭据

使用用户名密码和githosting URL将此内容添加到该文件

https://user:pass@example.com

然后执行命令

git config --global credential.helper store

现在,您将能够轻松推送并从回购中获取所有详细信息。

来源:设置Git

以下命令将在内存中保存密码一段时间(对于Git 1.7.10或更高版本)。

$ git config --global credential.helper cache
# Set git to use the credential memory cache

$ git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after one hour (setting is in seconds)

您需要执行两个步骤-

git远程删除原点git远程添加原点git@github.com:掘金AI/掘金.git

注意Git URL是SSH URL,而不是HTTPS URL。。。您可以从这里选择:

使用Git存储库永久验证

运行以下命令以启用凭据缓存:

$ git config credential.helper store
$ git push https://github.com/owner/repo.git

Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>

您还应该指定缓存过期,

git config credential.helper 'cache --timeout 7200'

启用凭据缓存后,将缓存7200秒(2小时)。43200秒=12小时(每天登录一次)对某些人来说可能也是一个合理的选择。


正如SebastianH所评论的,也可以使用类似的命令来配置,而不是按存储库,而是全局配置:

git config --global credential.helper credential.helper store
git config --global credential.helper 'cache --timeout 7200'

对我有用的是编辑.git/config并使用

[remote "origin"]
        url = https://<login>:<password>@gitlab.com(...).git

不用说,这是一种不安全的密码存储方式,但在某些环境/情况下,这可能不是问题。