首先你要有一个Github账号,没有的话去官网申请
第一步,配置ssh Key
1.设置你Github的name和email
$ git config --global user.name "gunmm"(引号里面是你自己的git用户名)
$ git config --global user.email "2031539819@qq.com" (引号里面是你的git账号的邮箱 就是你git账号设置中有一个绿色primary按钮标记的那个邮箱)
2.查看是否有ssh秘钥:$ cd ~/.ssh
没有就没有.ssh这个文件夹 ,有的话备份删除
3.生成密钥
ssh-keygen -t rsa -C"2031539819@qq.com"
按3个回车密码为空(第一个回车是问你存要存的位置和给文件取的名字,回车就是选默认的 后面两个是密码 回车就是不设密码 要是输入了就记住 会用到)
然后就给你提示:
Your identification has been saved in /Users/minzhe/.ssh/id_rsa.
Your public key has been saved in /Users/minzhe/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0Nv15mLHmHno+.....
说明生成成功了,得到两个文件
4.添加密钥到ssh:ssh-add 文件名(刚才输密码的现在就要用了)
或者去对应文件夹找到id_rsa.pub 打开(我用的sublime text)直接拷贝那串字符
5.在Github上添加ssh秘钥
登录你的Github账号 Setting>SSH and GPG keys>然后新建跟着弄就行
6.测试:ssh git@github.com
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? (输入yes)
第二步、登录Github创建仓库
new repository 然后填写名字和描述 勾选上initialize this repositories with README 然后点击Creat repositories 创建
第三部、上传代码
1.cd到项目文件夹
2.$ git init
3.$ git add -A
4.$ git remote add origin 你创建的仓库地址 (点击 绿色的clone or download 就出来了 类似这样https://github.com/gunmm/SwiftPractice.git)
5.$ git commit -m "commit的信息描述"
6.$ git pull --rebase origin master 更新远程更新到本地
7$ git push origin master(git push -u origin master) 第一次用 -u
8.$ git pull
好了成功了这样就有了