本地项目提交到GitHub
2016-07-12 本文已影响733人
Style_伟
本地已有项目,想提交到github,中间遇到问题,最终解决,记录如下:
- 1.在github创建仓库,方法如图:



- 2.添加本机项目
- 1.(cd xxx)cd到项目文件夹
- 2.(touch README.md)假如在github创建仓库的时候没有添加README文件,先创建文件
- 3.(git init)git初始化项目
- 4.(git add *)添加所有文件
- 5.(git commit -m "注释")提交注释
- 6.(git remote add origin git@github.com:xxxxxxx/YPhotoAutoLayout.git) 连接远程仓库
- 7.(git push -u origin master)提交到远程仓库,刷新网页,看到添加成功

疑难问题解答
- 1.提示出错信息:fatal: remote origin already exists.
- 1 先输入$ git remote rm origin
- 2 再输入git remote add origin git@github.com:xxxxxxx/YPhotoAutoLayout.git
- 3 如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容
- 4 找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
- 5 找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!
-
2.错误 error:failed to push som refs to .......
这是因为远程仓库和本地仓库不匹配,远程仓库有本地仓库没有的文件,需要先合并,再push- 解决方法:可以通过如下命令进行代码合并【注: pull=fetch+merge]
git pull --rebase origin master
然后再 git push -u origin master即可
```

-
3.错误
QQ20161117-0@2x.png
这是由于SSH不能验证导致的错误,解决办法,删除github上的SSH,再创新创建一个SSH导入github就可以了

创建SSH方法:
查看ssh版本 $ ssh –v
打开终端,$ ssh-keygen 一路enter下。
在Mac上生成SSH Key(在终端输入下面指令)
cd ~/.ssh
ssh-keygen -t rsa -C "你的邮箱地址”
然后一直敲回车
然后就会在~/.ssh目录下生成SSK Key的秘钥对
id_rsa :私钥,不可泄露
id_rsa.pub :公钥,可以公开(将这个文件的内容粘贴到GitHub上)
利用cat指令可以查看文件的内容
cat id_rsa.pub