本文将介绍在mac(windows下同理)下如何将本地项目上传到 Github。
一、准备
1、注册 github 账号 地址:https://github.com 具体方法本文不做介绍啦。 2、安装 Git 客户端 地址:https://desktop.github.com 正常安装即可,这里也不多做介绍啦。 3、准备好要上传的项目, 比如我们这里有一个小项目,我们把需要上传的项目文件放到一个位置,任意位置即可。二、首次使用
1、打开终端,定位到项目文件夹 2、然后输入命令: git init
3、然后配置 ssh , 输入:ssh-keygen -t rsa -C "847064370@qq.com" (邮箱替换成你登录github的邮箱)
4、这个地方请注意,它会在你选择的路径下上生成 ssh key,如果你直接点击回车,会在默认路径下创建 ssh 。如果你有多个项目,那么请配置不同的路径,或者一个路径换个文件名,我就用:/Users/liuyanzhao/.ssh/id_rsa 作为演示。输入路径之后点击回车。
5、这个地方是要你输入密码,直接回车则是不设置密码。直接回车就可以。然后会让你重复密码,也是直接回车。 

当你出现如图所示,就代表 ssh 已经生成了。
6、然后执行命令:
pbcopy < ~/.ssh/id_rsa.pub 这个的作用是将你的 ssh 代码复制到剪贴板。

7、现在,咱们在重新回到 github 页面,需要将刚才生成的 ssh 配置到 github 里。点击你的呆萌头像: 

8、点击左侧的 SSH and GPG keys,然后点击右上角的 New SSH key 按钮,最后将刚才复制的 ssh key 粘贴进去

9、现在,咱们再打开终端,验证一下是否添加ssh成功了,输入命令: ssh -T git@github.com 如果出现
报错,试着 ssh -T 847064370@qq.com (邮箱替换成你登录github的邮箱) 至于那个报错,暂时不管。
- The authenticity of host 'github.com (192.30.255.113)' can't be established.
- RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
- Are you sure you want to continue connecting (yes/no)? ssh -T 847064370@qq.com
- Please type 'yes' or 'no': yes
- Warning: Permanently added 'github.com,192.30.255.113' (RSA) to the list of known hosts.
- Hi saysky! You've successfully authenticated, but GitHub does not provide shell access.
报错,试着 ssh -T 847064370@qq.com (邮箱替换成你登录github的邮箱) 至于那个报错,暂时不管。
10、然后执行下面两条命令(注意修改用户名和邮箱) git config --global user.name "saysky" git config --global user.email "847064370@qq.com" 

11、现在咱们就可以上传代码啦!!将你的项目代码拉到这个文件夹,执行命令 git status 

12、然后执行 git add . (有个点哦,这个点表示更改所有的改动) 

13、然后执行命令 git commit -m "第一次更新"

14、然后执行命令:git remote add origin git@github.com:用户名/项目名.git (后面的地址从下面标注的地方可以找到
15、最后执行命令:git push -f origin master
16、现在 回到你的 github 页面,然后刷新该项目页,文件已全部上传了。 



注意:第2步到第10步这里是给本地电脑授权,不需要每次创建一个项目都要做,只需要做一次即可
三、以后使用
上面第2步到第10步只是第一次使用的时候需要弄,以后再创建新的项目,不需要那么多步骤 只需要以下几步 在 github 网页上新建一个仓库,然后复制SSH链接 然后切换到本地项目目录,只需如下几行命令,就可以上传代码到 github 上
git init
git add .
git commit -m "first commit"
git remote add origin git@github.com:saysky/SpringBlog-.git
git push -u origin master
参考:http://www.cnblogs.com/lijiayi/p/pushtogithub.html
2018年05月15日 09:30:49
学习了,准备在整理转载下,谢谢博主!