windows10 上 git 配置 github 和 gitee

windows10 上 git 配置 github 和 gitee

  1. git下载及配置
    下载:https://git-scm.com/downloads
    安装直接下一步就好。。。。
    配置:(https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration)

    $ git config --global user.name "你的名称"
    $ git config --global user.email 邮箱号
    
  2. 生成 github 和 gitee 的 SSH key

    a. 打开 git Bash,运行下面的命令,过程中直接按 Enter 就行

    $ ssh-keygen -t rsa -C 'github邮箱号' -f ~/.ssh/id_rsa_github
    $ ssh-keygen -t rsa -C 'gitee邮箱号' -f ~/.ssh/id_rsa_gitee
    

    b. 这时会在你的用户家目录(W:C:\Users/windows账户名.ssh,L/M:~/.ssh)下生成以下文件:
    01

  3. 分别登录githubgitee添加SSH KEY(下面以gitee为例)

    进入个人的设置目录:
    02
    需要注意的是,公钥一栏复制的时上述生成文件中的.pub文件的内容,即:id_rsa_gitee.pub

  4. 配置config文件
    进入.ssh目录下,新建config文件

    $ cd ~/.ssh
    $ touch config
    $ vim config
    

    输入以下内容:

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

    保存退出即可

  5. 测试

    $ ssh -T [email protected]
    Hi dubulingbo! You've successfully authenticated, but GITEE.COM does not provide shell access.
    $ ssh -T [email protected]
    Hi dubulingbo! You've successfully authenticated, but GitHub does not provide shell access.
    

    出现上述结果就证明配置成功!

猜你喜欢

转载自blog.csdn.net/dubulingbo/article/details/108549185