zoukankan      html  css  js  c++  java
  • windows 下部署多个git账户(gitee、github)

    1. 清除 git 的全局设置(针对已安装 git)

    新安装 git 跳过。

    若之前对 git 设置过全局的 user.name 和 user.email
    类似 (用 git config --global --list 进行查看你是否设置)

    $ git config --global user.name
    "你的名字" $ git config --global user.email "你的邮箱"

    必须删除该设置

    $ git config --global --unset user.name "你的名字"
    $ git config --global --unset user.email "你的邮箱"

    2. 生成新的 SSH keys

    打开git bash 运行

    1:先配置github

    生成一个github用的SSH-Key密钥:输入命令:(id_rsa_github是生成公钥的名)

    在指定的 .ssh 目录下 运行

      

    ssh-keygen -t rsa -C "yourname@email.com"

    或者

    $ ssh-keygen -t rsa -C '你的邮箱' -f ~/.ssh/id_rsa_github

    2:配置gitee

    生成一个gitee用的SSH-Key密钥:输入命令:(id_rsa_gitee是生成公钥的名)

    在指定的 .ssh 目录下 运行

    ssh-keygen -t rsa -C "yourname@email.com"

    直接回车3下,什么也不要输入,就是默认没有密码。

    3:查看公钥 添加到对应账号下的

     命令:

      

    cat id_rsa_github.pub

    3. 配置config文件

    需要在.ssh文件夹下新建config文件,先新建config.txt,然后修改文件名去掉后缀。

    config文件内容如下:

    其中第二行和第三中 需要填写gitlab的仓库地址

    # gitee1
        Host 1.gitee.com
        HostName gitee.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa_gitee
        User 账号邮箱
    # gitee2
        Host 2.gitee.com
        HostName gitee.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa_gitee
        User 账号邮箱 
    
    # github
        Host github.com
        HostName github.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa_github
        User 账号邮箱
    ————————————————
     
    
    # 配置文件参数
    # Host : Host可以看作是一个你要识别的模式,对识别的模式,进行配置对应的的主机名和ssh文件 /每个Host主要配置HostName和IdentityFile即可
    # HostName : 要登录主机的主机名
    # User : 登录名
    # IdentityFile : 指明上面User对应的identityFile路径
    Host github.com /*服务器地址为github地址*/
    
    User "XXX@XX.com" /*github上的注册邮箱为用户账号*/
    
    Hostname ssh.github.com /*服务器地址为github地址*/
    
    PreferredAuthentications publickey /*采用公匙*/
    
    IdentityFile ~/.ssh/id_rsa /*公匙文件路径*/
    
    Port 443 /*修改端口为443*/

    4. 测试

    $ ssh -T git@1.gitee.com
    $ ssh -T git@2.gitee.com
    $ ssh -T git@github.com


    5,Git配置多用户和邮箱

    Git的用户信息配置
    Git的配置一共有三个级别:system(系统级)、global(用户级)和local(版本库)。system的配置整个系统只有一个,global的配置每个账户只有一个,local的配置取决于Git版本库数量,在版本库才能看到。
    从Git官网的资料来看,这三个级别是逐层覆盖的。首先去查找system配置,其次查找global配置,最后查找local配置。逐层查找的过程中若查到配置值,则会覆盖上一层的配置。假如三个级别都配置了用户信息,则最后生效的配置是local(版本库)级的。

    Git配置用户名邮箱的命令
    system配置

    git config --system user.name "username"
    git config --system user.email user@email.com

    global配置

    git config --global user.name "username"
    git config --global user.email user@email.com

    local配置

    git config --local user.name "username"
    git config --local user.email user@email.com
  • 相关阅读:
    智能指针的理解
    [转] weak_ptr解决shared_ptr环状引用所引起的内存泄漏
    模板实现多态的功能
    Protobuf的自动反射消息类型的方法
    [转] C++临时变量的生命周期
    C++转换函数
    [转] boost------ref的使用(Boost程序库完全开发指南)读书笔记
    c++回调编程本质
    New 和 GetMem 的不同之处
    Delphi New,Getmem,ReallocMem联系与区别
  • 原文地址:https://www.cnblogs.com/qingjiawen/p/13234229.html
Copyright © 2011-2022 走看看