Git 关联到GigHub

创建 SSH Keygen

使用ssh-keygen生成私钥和公钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/yog/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/yog/.ssh/id_rsa.
Your public key has been saved in /c/Users/yog/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0ZYdnPILyMbV9xpgRE/hWf1MayqhoEYquZTuOMr8EcE yog@YOG-DESKTOP
The key's randomart image is:
+---[RSA 3072]----+
| =+.o.o|
| . .oo*=.oo|
| E o.o++.o++o|
| .. .=o... .o+|
| o.o ..S ....oo |
| = ..o . .... |
|o o.. . |
|=o . |
|==.. |
+----[SHA256]-----+

找到 SSH 公钥输出内容,也可以用资源管理器打开复制

1
2
3
4
5
6
$ cd ~/.ssh
$ pwd
/c/Users/yog/.ssh
$ cat id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDb9FSAEzrtUG9bJFt5oaDieFo6FeqBWB9ppX4VCqBnNxKvpnAZbJMjUjxHAIQEFSK2sD9NUXgyuKguilX6kRVGoTq15Lcf12nfqfjoGMUm3qAgNdZlkHPFk7WxBFquaalWV8OOOZNe45W2YcbzPucQMt54iiGSYzuAQLbMW/5rn2uF4HPrQNeMmduIvNZ8BxK4gS60IyjnEPTZbyG3RfJ0K5FQBN6wudoSWZZCU4UTcOjFhLRQ3I/p5OQTSKXnbBhpoX7nD42Xohijt2xB5GhdLrh42E28AEORchaMJ7OxqenT4U+BDdhQPk87ZBpB254Cv5RCvj60dJv5VjE/kTx4bCKslv9kgtV4INyUNPWlDAPhe6dmW1L+9Cl5QUYPvhjlXLLpcXoqne3OlPcS33UwJE0H/6++TusANaMTAXxPofD9XCgK/ipCNtT+YPxiyWIVJKgVUJ7NKAoieNOqXVN5d09ts/hSM5CtBXFbKnFGrPEr9zGiUhfe7HM0gRpWMV0= yog@YOG-DESKTOP

复制输出的全部公钥内容

开坑多个 SSH_Key 多个 GitHub 账户

1
ssh-keygen -t rsa -C "Exam@email.com" -f ~/.ssh/id_rsa_for_Exam

在 GitHub 上添加 SSH key

登陆 GitHub ,点击右上角头像,在弹出的菜单中选择 Settings 进入设置页

在右侧 Personal settings 中选择 SSH and GPG keys

点击 New SSH key,在 Key 中粘贴复制的公钥内容,然后 Add SSH key 完成 SSH key 添加

创建 GitHub 仓库

同样点击右上角头像,在弹出的菜单中选择 Your repositories 进入资源库页


在页面中间靠右点击 New 按钮

输入 Repository name 然后点击 Create repository 按钮

Description:可选输入一段描述,仓库选择 Public 和 Private 都可以。

资源库创建完成后,复制页面中的 git remote add 命令,回到 Git Bash

回创建的本地 Git 库中,运行复制的 git remote add 命令,关联本地库到 GitHub 远程库上

1
2
3
$ cd E:/GitLibrary/git_demo

$ git remote add origin git@github.com:yogwang/demo_repositories.git

使用 git push 命令把本地库的所有内容推送到远程库上

1
git push -u origin master

然后刷新 GitHub 库页面就可以看到上传的本地库文件了