使用 Git 生成 SSH Key 并将项目上传到 GitHub

官方下载git:

https://git-scm.com/

密钥部分:

2.打开Git Bash 并输入 $ ssh-keygen -t rsa -b 4096 -C "2653208961@qq.com"

$ ssh-keygen -t rsa -b 4096 -C "2653208961@qq.com"

3.默认设置空密码,连续按 3 次回车(如果不设置空密码则从按第一次enter后设置密码)

4.打开 C盘/用户/Administrator/.ssh 文件夹里面的 id_rsa.pub ,将里面的内容复制

5.粘贴到 GitHub =》Setting =》SSH and GPG keys =》New SSH Key 里面 (title随便写)

6.测试验证密钥是否添加成功,打开Git Bash 输入 $ ssh -T git@github.com  (不行的话输入 $ ssh git@github.com ),只要回车看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github 了

上传部分:

7.接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们(IDE打开项目)

git config --global user.name "wuaidongfang"

git config --global user.email "2653208961@qq.com"

git init   //创建.git文件

git add .    //将文件放入暂存区

git status   //查看文件状态

git commit -m "init my project"   //提交项目(注意:提交到的是本地git中去)

git remote add origin https://github.com/wuaidongfang/shopping.git   //与github中的shopping存储库建立连接(wuaidongfang 是我的github ID)

git push -u origin master  //将项目push上去

8.项目上传成功了

9.项目修改过的重新上传GitHub

git add .

git commit -m "init my project"

git push -u origin master
原文地址:https://www.cnblogs.com/wuaidongfang/p/10398426.html