Git从入门到精通
Git
不完全教程
Git
安装
Windows
:
官网:https://git-scm.com/download/win
Linux
:
官网:https://git-scm.com/download/linux
Mac
:
官网:https://git-scm.com/download/mac
连接使用
打开
git bash
,使用命令生成ssh公钥和私钥ssh-keygen -t rsa -C '[email protected]'
,一路回车git bash
使用命令查看生成的密钥cat ./.ssh/id_rsa.pub
,复制输出的内容到相应Git
系统GitLab
:Github
:
添加多个Git密钥
生成一对密钥
ssh key
,forGitLab
1
ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gitlab-rsa
生成一对密钥
ssh key
,forGithub
1
ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github-rsa
在
./ssh
文件夹下新建文件名为config
,用于管理多个ssh key
。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27# 两个Github
Host github-user1
HostName github.com
User git
IdentityFile ~/.ssh/my_new_key
Host github-user2
HostName github.com
User git
IdentityFile ~/.ssh/my_other_key
# GitLab加Github
Host gitlab-user1
HostName gitlab.example.com
User git
IdentityFile ~/.ssh/my_new_key
Host github-user2
HostName github.com
User git
IdentityFile ~/.ssh/my_other_key
# ssh-keygen -t rsa -b 4096 -C "my_new_key" -f ~/.ssh/my_new_key
# HostName github.com表示要连接到远程主机的名称或IP地址。在这个例子中,它们都连接到GitHub的主机。
# User git将SSH连接的用户名设置为Git,这是GitHub默认的SSH用户名。
# IdentityFile选择项指定了私钥文件的路径,为每个用户的SSH连接分配了不同的私钥文件。在这个例子中,第一个用户的私钥文件的路径为,第二步路径~/.ssh/my_new_key为~/.ssh/my_other_key。当使用不同git用户时,需要你更改一部分输入对应config内容。
1
git clone git@github-user1:user/repo.git
参考文献:
- [图解