如何覆盖一次回购的全局Git凭据?

如何覆盖一次回购的全局Git凭据?,git,config,credentials,Git,Config,Credentials,如果我设定 git config --global credential.username my_username 选项,然后使用--local选项为一个存储库覆盖它,对它没有任何区别-它在尝试提交或推送时仍然使用全局凭据。我怎样才能改变这个 如果没有为网络身份验证设置用户名,则默认情况下使用此用户名 您可能在--global上配置了user.name,因此不使用--local上的凭证.username。试试这个: git config --local user.name my_userna

如果我设定

git config --global credential.username my_username
选项,然后使用
--local
选项为一个存储库覆盖它,对它没有任何区别-它在尝试提交或推送时仍然使用全局凭据。我怎样才能改变这个

如果没有为网络身份验证设置用户名,则默认情况下使用此用户名

您可能在
--global
上配置了
user.name
,因此不使用
--local
上的
凭证.username
。试试这个:

git config --local user.name my_username

回购本地配置对我不起作用。在尝试了stackoverflow的各种方法之后,它最终通过从ssh切换到https并使用credential.helper工作:

步骤1,将git remote从ssh更改为https:

$ git remote -v
    git@github.com:#####/###.git (push)

$ git remote rm origin
$ git remote add origin https://username@github.com/######/###.git
第2步,让credential.helper帮助记住密码,避免烦人的重复询问

$ git config --global credential.helper cache
$ git config --global credential.helper 'cache --timeout 7200'
默认情况下,凭据将保存在~/.git凭据中。它将被创建并写入


但请注意使用此帮助程序将未加密的密码存储在磁盘上,仅受文件系统权限的保护。如果这可能不是一个可接受的安全权衡。

您确定存储库的
.git/config
文件已更新吗?@chepner是,它包含
username
myproject/.git/config
选项。在这样的情况下,我发现使用
~/.gitconfig
myproject/.git/config
启动编辑器更方便。精确地显示您设置的选项,语法非常简单。提交时使用此设置,但推送仍使用全局凭据设置。