由于我电脑上有多个仓库,GitHub上一个,GitLab上有一部分,用户名和账号不同,邮箱也不一样,而且这些项目都是活跃项目,需要频繁提交,这个时候就需要配置多个用户,进行不同的仓库的操作。
  • 清除之前的全局配置

    #查看git设置
    git config --list 
    
    #重制用户名和邮箱
    git config --global --unset user.name
    git config --global --unset user.email
  • 设置新的用户名以及邮箱

    #配置单独配置用户名信息
    git config --local user.name "username"
    git config --local user.email email address
    
    #配置全局用户名信息
    git config --global user.name "username"
    git config --global user.email email address
  • Git记住用户名以及密码

    • 对于单个Git仓库而言,只需要编辑主目录下的.git/config文件。在文件最后添加以下内容
    [credential]
                    helper = store
    • 对于全局仓库,只需要输入一行命令
    git config --global credential.helper store
  • 其他参考文件:

    [1] Git储存多个用户名和密码

    [2] Git配置多个用户ssh密钥

最后修改:2022 年 09 月 02 日
如果觉得我的文章对你有用,请随意赞赏