git远程仓库的连接和远程库到本地的克隆

学习目标:

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 1023 04:01 test1
-rw-r--r--. 1 oot root 10 1023 03:03 yyt.txt
[root@192 test]# cd test1/
[root@192 test1]# ls -l
总用量 4
-rw-r--r--. 1 oot root 7 1023 04:01 README.md
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值