< 笔记 > Git - 05 Git 远程仓库

05 Git 远程仓库

By Kevin Song

  • 05-01 添加远程库
  • 05-02 从远程库克隆

早期:

  • 一台电脑充当服务器,7 x 24 开机
  • 别的机器可以克隆原始版本库

现在: GitHub(Git仓库托管服务)

本地Git仓库和GitHub仓库之间的传输是通过SSH加密:

1 . 创建SSH Key

  • 用户主目录下有没有 .ssh 目录
    • .ssh 目录下有没有 id_rsaid_rsa.pub 这两个密钥对。如果有直接去步骤 2
      • id_rsa:私钥
      • id_rsa.pub :公钥
    • 用户主目录下没有 .ssh 目录
      • 打开 Git Bash 创建SSH Key
$ ssh-keygen -t rsa -C "youremail@example.com"

2 . 登陆Github - Settings - SSH and GPG Keys

  • New SSH key
    • Key文本框里粘贴 id_rsa.pub 文件内容

SSH加密:GitHub 用SSH公钥识别是用户自己推送的

GitHub默认公有仓库,创建私有仓库方法

  • 方法一:GitHub付费7刀一个月
  • 方法二:搭建自己的Git服务器

05-01 添加远程库

本地Git仓库和GitHub仓库远程同步

1 . 登陆GitHub - New repository

  • Repository name:learngit
    • Create repository

2 . 在本地的learngit仓库下运行命令:

$ git remote add origin git@github.com:KevinJtSong/learngit.git

origin 是远程库的名字,是Git默认叫法,可以改成别的

3 . git push 把本地库的所有内容推送到远程库

  • 第一次推送master分支加上 -u 参数
    • Git把本地的master分支内容推送的远程新的master分支
    • Git把本地的master分支和远程的master分支关联起来
$ git push -u origin master
Counting objects: 16, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (16/16), 1.31 KiB | 0 bytes/s, done.
Total 16 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), done.
To git@github.com:KevinJtSong/learngit.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

4 . git push 把本地master分支的最新修改推送至GitHub

$ git push origin master

SSH警告

第一次使用Git的clone或者push命令连接 GitHub 会得到一个警告:

The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?

输入yes回车:

Warning: Permanently added 'github.com' (RSA) to the list of known hosts.

警告目的:防止有人冒充GitHub服务器违法窃取用户提交的文件

05-02 从远程库克隆

先创建GitHub仓库再克隆到本地Git

  1. 登陆GitHub新建仓库叫gitskills
  2. 命令git clone克隆一个本地库
$ git clone git@github.com:KevinJtSong/gitskills.git
Cloning into 'gitskills'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

$ cd gitskills
$ ls
README.md
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值