学习目标:
GIT学习三、
学习内容:
1、远程库添加
2、从远程库克隆
1、远程库添加
1、步骤
在网页中搜索github并打开
- 首先需要一个github的账号,然后create respository新建一个远程库
- 跳转界面之后,在ower处填写github的用户名,在repository name处填写本地的版本库的文件名
- 然后在本地版本库中生成公钥,然后用cat读取公钥并复制
ssh-keygen -t rsa -C "xxxxxxx@qq.com"获取公钥
[root@192 test]# ssh-keygen -t rsa -C "xxxxxxx@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:n+o7/Y8+0bWehf35Cc9A8IleR+jEgA3FiJa6m8xC2aA xxxxxxx@qq.com
The key's randomart image is:
+---[RSA 3072]----+
| o.Bo |
| + o oo . |
| o . + . |
| . . * o .|
| . + . S . B =.|
| E o o ...+ +.o|
| . o o .o. +. =|
| . = ... ..=+o|
| . .+o o+o.+o|
+----[SHA256]-----+
[root@192 test]# cat id_rsa.pud
- 将复制的公钥粘贴到创建的远程版本库中 setting—>deploy keys的key处,title随便写然后Add key
- 回到本地版本库的文件夹中,与远程版本库进行连接并且将本地的版本库推送到远程版本库中,
git remote add origin git@github.com:yyt-wy/远程版本库名.git
连接到版本库(命令中的yyt-wy需改成自己的github账号)
git push -u origin master是将本地的版本库推送到远程版本库master
[root@192 test]# git remote add origin git@github.com:yyt-wy/test.git
[root@192 test]# git push -u origin master
The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
枚举对象: 3, 完成.
对象计数中: 100% (3/3), 完成.
写入对象中: 100% (3/3), 202 bytes | 202.00 KiB/s, 完成.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/yyt-wy/test/pull/new/master
remote:
To github.com:yyt-wy/test.git
*[new branch] master -> master
分支 'master' 设置为跟踪来自 'origin' 的远程分支 'master'。
2、从远程库克隆
- 登录网页远程github,创建一个新的库名叫test1,并勾选Add a README file
- 创建完毕后,可以看到README.md文件:
- 远程库已经准备好,接下来用命令git clone克隆一个本地库
git clone git@github.com:github用户名 / 远程库创建的库名.git
[root@192 test]# git clone git@github.com:yyt-wy/test1.git
正克隆到 'test1'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
接收对象中: 100% (3/3), 完成.
- 最后你会发现本地库中已经有了从远程库克隆的文件夹tes1,进入文件夹查看有没有readme这个文件
[root@192 test]# ls -l
总用量 4
drwxr-xr-x. 3 oot root 35 10月 23 04:01 test1
-rw-r--r--. 1 oot root 10 10月 23 03:03 yyt.txt
[root@192 test]# cd test1/
[root@192 test1]# ls -l
总用量 4
-rw-r--r--. 1 oot root 7 10月 23 04:01 README.md