- https://github.com 官网注册登陆
- 在页面上方用户菜单上选择 “+” → New repository 创建一个新的仓库
-
$ git init
- 在本地创建ssh key 后面的your_email@youremail.com改为你的邮箱。我的邮箱是haha@qq.com,也是在github上注册的那个邮箱
-
$ ssh-keygen -t rsa -C "haha@qq.com"
- 直接点回车,说明会在默认文件id_rsa上生成ssh key。
- 然后我们进入提示的地址( C:\Users\用户名.ssh)下查看ssh key文件。打开id_rsa.pub,复制里面的key。
- 回到github网站,进入Account Settings,左边选择SSH and GPG keys,Add SSH Key,title随便填,粘贴key。
- 验证是否成功,在git bash下输入
$ ssh -T git@github.com
- 接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们(记录谁上传修改的)
$ git config --global user.name "your name" $ git config --global user.email "your_email@youremail.com"
- 进入要上传的仓库,右键git bash,添加远程地址
$ git remote add origin git@github.com:yourName/yourRepo.git $ git add README.md $ git commit -m "first commit" $ git push origin master
- 回退的bash命令:
$ git reset --hard $ git push -f
- 比较的bash命令:
$ git status
友情链接 参考:https://www.cnblogs.com/cxscode/p/8325064.html