1、本次连接的是gitHub仓库。
1》创建SSH Key。
ssh-keygen -t rsa -C "youremail@example.com"
lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master) $ ssh-keygen -t rsa -C "12345678@qq.com" Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/lfy/.ssh/id_rsa): Created directory '/c/Users/lfy/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/lfy/.ssh/id_rsa. Your public key has been saved in /c/Users/lfy/.ssh/id_rsa.pub. The key fingerprint is: SHA256:88888888888888888jY888888888I8 12345678@qq.com The key's randomart image is: +---[RSA 2048]----+ | ....... | | | +----[SHA256]-----+ lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master) $
2》将公钥添加到ssh key列表。
3》在gitHub上创建一个新的库,然后使用命令将我们的本地库与之关联。
$ git remote add origin git@github.com:michaelliao/learngit.git
添加后,远程库的名字就是origin
,这是Git默认的叫法,也可以改成别的,但是origin
这个名字一看就知道是远程库。
4》将已经与远端库关联的本地库的内容推送到远端库。
$ git push -u origin master
本地库的内容推送到远程,用git push
命令,实际上是把当前分支master
推送到远程。由于远程库是空的,我们第一次推送master
分支时,加上了-u
参数,Git不但会把本地的master
分支内容推送的远程新的master
分支,还会把本地的master
分支和远程的master
分支关联起来,在以后的推送或者拉取时就可以简化命令。
2、克隆远端库
$ git clone git@github.com:michaelliao/gitskills.git Cloning into 'gitskills'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 3 Receiving objects: 100% (3/3), done.