q66262 发表于 2018-1-15 10:42:52

【 js 工具 】如何使用Git上传本地项目到github?(mac版)

  在此假设你已经在 github 上创建好了一个项目,像这样:
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027170911828-1794986129.png
  并且你已经完成了自己的项目代码,
  同时你也已经安装了 git,然后 let's start.
  首先,建一个文件夹比如文中演示的是 微信小程序 文件夹,然后打开的你的终端,定位到该文件夹,
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027172358906-72399499.png
  然后输入命令: git init
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027172953312-1730421495.png
  然后配置 ssh , 输入:ssh-keygen -t rsa -C "jiayi_li10@163.com" (邮箱替换成你登录github的邮箱)
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027173953656-144874860.png
  这个地方请注意,它会在你选择的路径下上生成 ssh key,如果你直接点击回车,会在默认路径下创建 ssh 。如果你有多个项目,有工作的,有自己玩的,那么请配置不同的路径,或者一个路径换个文件名,我就用:/Users/lijiayi/.ssh/id_test_rsa 作为演示。输入路径之后点击回车。
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027174405484-372910920.png
  这个地方是要你输入密码,直接回车则是不设置密码。直接回车就可以。然后会让你重复密码,也是直接回车。
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027174543375-1805496485.png
  当你出现如图所示,就代表 ssh 已经生成了。
  这个执行命令:pbcopy < ~/.ssh/id_test_rsa.pub   这个的作用是将你的 ssh 代码复制到剪贴板。
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027175018156-1238220010.png
  现在,咱们在重新回到 github 页面,需要将刚才生成的 ssh 配置到 github 里。点击你的呆萌头像:
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027175233578-197462996.png
  然后点击 settings 设置:
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027175343640-103608185.png
  点击配置 ssh:
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027175518828-365489384.png
  点击新建 New SSH key
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027175731734-400546959.png
  直接 Crl+v 将刚才你已经复制在剪贴板里的 ssh 复制到 key input 里面,title 你随意起喽。然后点击 Add SSH key.
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027175959578-1764241876.png
  现在,咱们再打开终端,验证一下是否添加ssh成功了,输入命令: ssh -T git@github.com
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027180322562-1629013139.png
  出现如上图的句子,你就起来跳个舞。倘若是类似如下的句子:
  

The authenticity of host 'git.net (116.211.167.152)' can't be established.  
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
  
Are you sure you want to
continue connecting (yes/no)? yes  
Warning: Permanently added
'git.oschina.net,116.211.167.152' (ECDSA) to the list of known hosts.  
Permission denied (publickey).
  

  或者permission denied,你就再执行命令:ssh-add ~/.ssh/id_test_rsa
  再次输入 ssh -T git@github.com 如果提示成功了,咱们就继续,如果没有成功,你就 google 一下报的什么错误。
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027214429515-682678881.png
  当你successfully之后,咱们就在 git config 里设置一下你的 github 登录名以及登陆邮箱,执行以下两个命令:
  git config --global user.name "your name"
  git config --global user.email "your_email@youremail.com"
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027203112859-1293539707.png
  现在咱们就可以上传代码啦!!
  将你的项目代码拉到这个文件夹,执行命令,git status
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027214607734-474422905.png
  这个时候你就会看到所有的改动,然后执行 git add .    (有个点哦,这个点表示更改所有的改动)
  then 执行命令 git commit -m "第一次更新"
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027214700671-578862850.png
  然后执行命令:git remote add origin git@github.com:用户名/项目名.git (后面的地址从下面标注的地方可以找到)
https://images2015.cnblogs.com/blog/903320/201702/903320-20170227232102298-1331410342.png
  最后执行命令:git push -f origin master
  现在 回到你的 github 页面,然后刷新该项目页,哇色,这是什么
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027205917375-424844407.png
  去跳舞吧~
  一些有可能遇到的问题以及参考网站:
  *mac多个git账户配置:http://www.jianshu.com/p/fbbf6efb50ba
  *cannot push to github ,keeps saying need merge: http://stackoverflow.com/questions/10298291/cannot-push-to-github-keeps-saying-need-merge
  *删除github远程分支:https://my.oschina.net/tsingxu/blog/84601
  记得点推荐和关注我哦~
https://images2015.cnblogs.com/blog/903320/201610/903320-20161027211049734-783798005.png  
页: [1]
查看完整版本: 【 js 工具 】如何使用Git上传本地项目到github?(mac版)