美文网首页
Git 为不同项目设置不同的 用户名 或 SSH Key

Git 为不同项目设置不同的 用户名 或 SSH Key

作者: 别瞄我 | 来源:发表于2020-03-04 15:13 被阅读0次

    需求

    有时候我们在公司需要提交代码给 Github 或其它第三方仓库,但我们不想使用公司项目相同的 user.name、user.email 或 SSH Key

    解决

    不想使用公司项目相同的 user.name、user.email

    进入项目目录,设置独立的 user.name、user.email

    cd /your_project
    git config user.name "your_name"
    git config user.email "your_email"
    

    不想使用公司项目相同的 SSH Key

    比如我现在想给我的 Github 项目设置一个独立的 SSH Key

    1. 生成一个新的key
    ssh-keygen -t rsa -C "xsplus007@gmail.com"
    
    1. 将 id_rsa_github.pub 里面的 key 配置到 Github


    2. 配置 config 内容
      ~/.ssh 目录下 config 文件(没有则创建)中添加如下内容:
    Host github.com
        HostName github.com
        IdentityFile ~/.ssh/id_rsa_github
    
    1. 验证是否成功

    如不成功可用 ssh -vT git@github.com debug 问题

    相关文章

      网友评论

          本文标题:Git 为不同项目设置不同的 用户名 或 SSH Key

          本文链接:https://www.haomeiwen.com/subject/emkmlhtx.html