git 同时管理github和gitee

如何使用git管理github和gitee

想必大家做开发,用的很多的代码托管无非就是github和gitee

但是, 我一直用的是github,对于gitee基本没用过

at today , 我遇到了一个问题,我团队需要使用码云了,what funk? so 我只能重新配置git的环境了,让它能同时存在github和gitee

show time

  1. 如果你用的只是github和gitee中的一款,那么你的git应该是配置一个全局的 user.name 和 user.email
  2. 你的id_rsa 也是通过github或者是gitee上注册邮箱生成的

很显然,如果需要两者皆存在,那么以上两点都是不能存在的,不能存在那么就要delete啊

1.刺激的delete

取消全局的user.name和user.email

git config --global --unset user.name "xxx"
git config --global --unset user.email "xxx"
# 其中 xxx 是你以前配置的信息,可以通过 
git confg --global --list 进行查看

2.生成new的ssh keys

​ 如果需要github和gitee都能存在,那么就需要生成github和gitee的id_rsa, 然后放在一起

  1. 生成github 和 gitee的keys

    ssh-keygen -t -rsa -f ~/.ssh/id_rsa.github -C "xxx"
    # 其中xxx是你github平台的注册邮箱
    ssh-keygen -t -rsa -f ~/.ssh/id_rsa.gitee -C "..."
    # 其中...是你gitee平台的注邮箱  
    
  2. 将生成的新keys添加到ssh agent

    ssh-agent bash
    ssh-add ~/.ssh/id_rsa.github
    ssh-add ~/.ssh/id_rsa.gitee
    
  3. 配置config文件

    在.ssh文件夹下面配置config文件

    # github
    Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa.github
    # gitee
    Host gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa.gitee
    

3.平台设置SSH

钥匙和配置文件搞定后,就需要将我们的公钥放入到我们的平台中了

  1. github

    setting > ssh and gpg keys > new ssh key

  2. gitee

    **设置 > 安全设置 > SSH公钥 **

  • 最后进行测试:

    ssh -T [email protected]

    result:

    Warning: Permanently added the RSA host key for IP address ‘13.250.177.223’ to the list of known hosts.
    Hi LaochouYzl! You’ve successfully authenticated, but GitHub does not provide shell access.

    ssh -T [email protected]

    result:

    $ ssh -T [email protected]
    The authenticity of host ‘gitee.com (120.55.226.24)’ can’t be established.
    ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added ‘gitee.com,120.55.226.24’ (ECDSA) to the list of known hosts.
    Hi BlueDot! You’ve successfully authenticated, but GITEE.COM does not provide shell access.

出现以上结果:: it indicate you did it, may be you should celebrate with a beer

你可能感兴趣的:(git 同时管理github和gitee)