我的git使用总结

关于git教程,网上已经有很多了。有时候遇到问题一阵搜索,问题解决了,下次我又遇到或者别人问我这类问题,我一时无法找到当时的那篇文章了,所以我这里记录一下,只为了方便自己查找。

我的环境:win10

环境搭建

  1. 下载最新git:https://gitforwindows.org/,安装
  2. 打开gitbash(cmd不行)输入
    1
    cd ~/.ssh // 其实就在用户目录下有个.ssh的文件夹

查看本机之前是否配置过,配置过直接跳第5步.

  1. 配置用户名和邮箱

    1
    2
    git config --global user.name "t450" // 我习惯用电脑型号, 这样公司和家里的电脑提交代码就容易区分了
    git config --global user.email "your_email@example.com"
  2. 创建SSH Key(经发现同一个id_rsa.pub可以连gitee和github)

    1
    ssh-keygen -t rsa -C "your_email@example.com"

把公钥文件中的 key 复制到 github 和gitee 的ssh公钥中

  1. 创建SSH Key(同时配置github和gitee)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ssh-keygen -t rsa -C "your_email@example.com" -f "github_id_rsa"
    ssh-keygen -t rsa -C "your_email@example.com" -f "gitee_id_rsa"

    // 创建.config文件解决ssh冲突,在.ssh下创建.config文件并添加:
    # github
    Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github_id_rsa

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

4.查看SSH Key
copy公钥内容到gitLab里,添加进去.

1
cat ~/.ssh/id_rsa.pub
  1. 测试是否连通
    1
    2
    ssh -T git@github.com
    ssh -T git@gitee.com

git技巧

参考

Author: kyxiao
Link: https://kyxiao.github.io/2019/07/15/我的git使用总结/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.