如何使用Git将代码更新到本地
第一步 -- 新建仓库
- 登陆GitHub
- 进入个人主页
- Start a project
- Repository name(项目名称)
- 勾选 Initialize this repository with a README的复选框,初始化项目
- 提交
- 进入导航栏Settings
- 修改GitHub Pages
- 修改None为master branch
- 得到url + ‘/’ +文件名
第二步 -- clone项目
-
选择clone with SSH
image.png
$ git clone git@github.com:xiangbajiang/MyBlog.git
- 这时候会有报错,提示你没有公钥以及私钥,此时需要你生成一个SSH KEY
$ git clone git@github.com:xiangbajiang/MyBlog.git
Cloning into 'MyBlog'...
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
- 本地创建公钥私钥对(引号里面写的你的github的邮箱地址)
$ ssh-keygen -t rsa -b 4096 -C ''xiangbajiang@gmail.com''
在生成过程中,一直按回车直到密钥生成就可以
密钥会生成再家目录下的~/.ssh/下,公钥是id_rsa.pub(给别人使,也就是github),私钥是id_rsa(自己用)
- 使用密钥,得到一串字符将其输入到github的个人设置里之后就可以安全clone了
$ cat ~/.ssh/id_rsa.pub
image.png
image.png
-
接下来就可以直接的git clone了
image.png
网友评论