Mac下提交本地项目到github超详细流程

       近期为了和同伴协同开发项目,想着自己搭建一个github仓库来上传代码,虽然从刚入行就一直使用git提交代码,但是是第一次从创建仓库开始。因为是小白我在网上搜了很多文档, 自己在实践的同时也遇到了一些问题,下面我把使用git把本地项目上传到github的流程写出来,也会把遇到的一些问题列出来供大家参考的同时也记录下方便自己记忆。废话不多说,下面开始进入正题:

安装git

安装方式: homebrew和Xcode

首先看下电脑是否安装Git,可以使用命令行查看

➜  ~ git

安装过控制台会显示:

Mac下提交本地项目到github超详细流程_第1张图片

  1. 通过homebrew安装 :        brew install git 
  2. 通过xcode安装

创建ssh,配置git

  • 设置username和email

➜  ~ git config --global user.name "missxxx"

➜  ~ git config --global user.email "[email protected]

  • 创建ssh key

➜  ~ ssh-keygen -t rsa -C "[email protected]"

输入命令行后一直回车就行

  • 查看.ssh/id_rsa.pub

用cat命令查看 复制key(ssh key以ssh-rsa 开头)

➜  ~ cat .ssh/id_rsa.pub

  • github上添加ssh key (流程如下图)

Mac下提交本地项目到github超详细流程_第2张图片

Mac下提交本地项目到github超详细流程_第3张图片

  • 链接验证

➜  ~ ssh -T [email protected]

提交本地项目到github

  • github新建repository(流程如下图)

Mac下提交本地项目到github超详细流程_第4张图片

Mac下提交本地项目到github超详细流程_第5张图片        点击create创建

  • 如图复制ssh地址

Mac下提交本地项目到github超详细流程_第6张图片

➜  ~ cd /Users/apple/Desktop/xxxx      (xxxx表示本地工程目录)

➜  intelligenceSystem-1 git:(master) git add .

➜  intelligenceSystem-1 git:(master) git commit -m "注释"

➜  intelligenceSystem-1 git:(master) git remote add origin [email protected]:xxxx.git        (链接远程仓库即上图复制的ssh地址)

➜  intelligenceSystem-1 git:(master) git pull origin master

遇到的问题

  • ➜  intelligenceSystem-1 git:(master) git push -u origin master

remote: You must verify your email address.

remote: See https://github.com/settings/emails.

fatal: unable to access 'https://github.com/xxx/xxxx/': The requested URL returned error: 403

解决方案: 使用如下命令找出电脑提交代码时使用的账号策略

➜  ~  git config --show-origin --get credential.helper

修改.gitconfig文件[credential] helper = osxkeychain改为helper = store并保存

  • ➜  intelligenceSystem-1 git:(master) git push -u origin master

Username for 'https://github.com': [email protected]

Password for 'https://[email protected]@github.com': 

To https://github.com/xxxx/xxxx.git

 ! [rejected]        master -> master (non-fast-forward)

error: 推送一些引用到 'https://github.com/xxx/xxx' 失败

提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。

提示:再次推送前,先与远程变更合并(如 'git pull ...')。详见

提示:'git push --help' 中的 'Note about fast-forwards' 小节

解决方案:将git push -u origin master命令 改为git push -u origin +master

你可能感兴趣的:(github,git)