1> GitHub创建账户
https://github.com/join?source=header-home
2> 安装Git
ubuntu:sudo apt install git
windows:https://git-scm.com/downloads
3> 生成ssh key
ssh-keygen -t rsa -C "用户名(用于备注)" //一直回车
4> 把 ~/.ssh/id_rsa.pub 文件里的内容添加到GitHub中
登录GitHub:Settings => SSH and GPG keys => New SSH key
5> 验证ssh key是否添加成功
ssh -T git@github.com
(注意红框标注)
Permission denied (publickey):失败
You’ve successfully authenticated:成功
6> 初始化本地仓库
在目标目录下执行:
git init
配置Git的username和email(提交代码时的用户信息):
git config --global user.name "your name"
git config --global user.email "your email"
查看配置信息:
git config user.name
git config user.email
7>创建Github仓库(Repository)
https://github.com/new
获取仓库地址:
8> 同步
拉取:
git pull git@github.com:Sepuer/JustTest.git //仓库地址
推送:
echo “test” > test.txt //创建测试文件
git add test.txt //把要提交的修改添加到暂存区(Stage)
git commit -m “first commit” //一次性把暂存区的所有修改提交到分支
git remote add origin git@github.com:Sepuer/JustTest.git //配置远程仓库地址(下次不用再配置)
git push -u origin master //推送至远程仓库(下次推送无需再带参数)
参数(-u origin master) 的作用是:分支 ‘master’ 设置为跟踪来自 ‘origin’ 的远程分支 ‘master’(官方描述)