Mac如何在Github上传代码

Mac如何在Github上传代码
步骤如下: 1、在Github上创建自己的账户 2、创建ssh 3、创建ssh key 连接到Github 4、在Github上创建自己的项目 5、将代码上传到Github 一、在Github上创建自己的账户
1. 打开Git官网:https://github.com
2. 注册账户:点击 sign up
Mac如何在Github上传代码
文章图片
git官网 3. 创建新仓库
点右上的?号,选择New repository
Repository name:自己选择填写
Description:选填,对自己项目的描述


Mac如何在Github上传代码
文章图片
Create repository 二、创建SSH
1. 打开mac终端上输入,设置本地ssh key
输入如下代码:ssh-keygen -t rsa -C "109256921@qq.com" (邮箱替换成你登录github的邮箱,这个地方请注意,它会在你选择的路径下上生成 ssh key,如果你直接点击回车,会在默认路径下创建 ssh 。如果你有多个项目,那么请配置不同的路径)
生成如下:
1) Overwrite可选y;
2) Enter passphrase可一直enter不设置,或可设置不少于4位数的密码(这个地方是要你输入密码,直接回车则是不设置密码。直接回车就可以)
三、创建ssh key连接到Github上
1) 登录Github,右上角点击你的头像选择settings


Mac如何在Github上传代码
文章图片
2)进入Personal settings后,选择SSH and GPG keys选项


Mac如何在Github上传代码
文章图片
点击新建 New SSH key


Mac如何在Github上传代码
文章图片
终端上输入:cd ~/.ssh/
在终端上显示key:cat id_rsa.pub
将key粘贴到Github的key上
Mac如何在Github上传代码
文章图片
现在,咱们再打开终端,验证一下是否添加ssh成功了,输入命令: ssh -T git@github.com
jindinguandeAir:.ssh jdyx$ ssh -T git@github.com
Hi shengss1! You've successfully authenticated, but GitHub does not provide shell access.
出现以上提示代表成功!
当你successfully之后,咱们就在 git config 里设置一下你的 github 登录名以及登陆邮箱,执行以下两个命令:
git config --global user.name "your name"
git config --global user.email "your_email@youremail.com"
克隆新建的项目到本地
git clone https://……(https是Github对应仓库的地址)
把待上传的文件拖入到该文件夹


将代码上传到Github
终端上输入如下:
git init#初始化本地仓库
git add . #将代码添加(.表示添加当前目录下所有)
git commit -m "第一次更新"
git remote add origin git@github.com:用户名/项目名.git(若添加错误可使用git remote rm origin删除添加)
git pull --rebase git@github.com:用户名/项目名.git
git push -u origin master#提交
【Mac如何在Github上传代码】上传代码到github到此就结束了,回到你的 github 页面,刷新看看效果

    推荐阅读