近期为了和同伴协同开发项目,想着自己搭建一个github仓库来上传代码,虽然从刚入行就一直使用git提交代码,但是是第一次从创建仓库开始。因为是小白我在网上搜了很多文档, 自己在实践的同时也遇到了一些问题,下面我把使用git把本地项目上传到github的流程写出来,也会把遇到的一些问题列出来供大家参考的同时也记录下方便自己记忆。废话不多说,下面开始进入正题:
首先看下电脑是否安装Git,可以使用命令行查看
➜ ~ git
安装过控制台会显示:
➜ ~ git config --global user.name "missxxx"
➜ ~ git config --global user.email "[email protected]"
➜ ~ ssh-keygen -t rsa -C "[email protected]"
输入命令行后一直回车就行
用cat命令查看 复制key(ssh key以ssh-rsa 开头)
➜ ~ cat .ssh/id_rsa.pub
➜ ~ ssh -T [email protected]
➜ ~ 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
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并保存
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