Git学习笔记(二)

远程仓库

创建SSH KEY,在主目录下会创建.ssh文件夹,文件夹包含id_rsa(私钥)和id_rsa.pub(公钥)文件:

$ ssh-keygen -t rsa -C "[email protected]"

将公钥信息添加到github账号,并测试:

$ ssh -T [email protected]

返回以下信息则表示设置成功:

Hi your_name! You've successfully authenticated, but GitHub does not provide shell access.

添加远程库

登录GitHub,点击Create a new repo按键创建一个新的仓库。目前这个仓库还是空仓库,我们可以从这个仓库克隆出新的仓库,也可以把一个已有的本地仓库与之关联,然后,把本地仓库的内容推送到GitHub仓库。

现在我们进入learngit目录运行以下命令来添加远程仓库:

$ git remote add origin https://github.com/username/learngit.git

接下来使用git push将本地文件推送到远程仓库:

$ git push -u origin master
Counting objects: 23, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (23/23), 1.92 KiB | 0 bytes/s, done.
Total 23 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), done.
To https://github.com/username/learngit.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

从远程库克隆

使用git clone命令可以将远程库克隆到本地。

Git支持多种协议:
https://github.com/username/learngit.git这样的地址为https协议,速度较慢,且每次都需要安全验证;
[email protected]:username/learngit.gitssh协议,ssh协议速度相对快,但是有些网络环境不开放端口所以只能用https协议。

你可能感兴趣的:(Git学习笔记(二))