GIt使用记录1:使用Git上传项目到Github
1、安装git
具体操作省略
2、配置GitHub仓库
1、创建仓库
![](https://img.haomeiwen.com/i3691899/b70e9282f7b051d4.png)
2、复制仓库地址
![](https://img.haomeiwen.com/i3691899/658a317885dbc5c9.png)
3、配置GitHub服务器的密钥
因为Git使用SSH连接,而SSH第一次连接需要验证GitHub服务器的Key。确认GitHub的Key的指纹信息是否真的来自GitHub的服务器。解决办法。其实就是在本地生成key配置到github服务器。
1)、在前面安装好的git bash中使用命令: ls -al ~/.ssh
![](https://img.haomeiwen.com/i3691899/9a3219aa27342240.png)
2)、使用命令: ssh-keygen -t rsa -C "github用户名",按三次回车
![](https://img.haomeiwen.com/i3691899/2edf92fc2a26b0f1.png)
3)、查看生成的key:cat ~/.ssh/id_rsa.pub
![](https://img.haomeiwen.com/i3691899/8a6fa6dd894a8c6f.png)
4)、登陆github,复制新生成的SSH配置到服务器,
![](https://img.haomeiwen.com/i3691899/dbde3aad07e50b27.png)
![](https://img.haomeiwen.com/i3691899/b0ca3572cbd71d17.png)
4、上传本地项目
1):打开git bash ,cd进入你放项目文件的地址,我的地址在D:\xxx\xx\项目
![](https://img.haomeiwen.com/i3691899/54e7d4806b616e37.png)
2):输入git init 这个意思是在当前项目的目录中生成本地的git管理(会发现在当前目录下多了一个.git文件夹)
![](https://img.haomeiwen.com/i3691899/7b3b41153fc04d31.png)
3)输入git add .
![](https://img.haomeiwen.com/i3691899/e637aaea70c2910e.png)
4)输入git commit -m "测试",表示你对这次提交的注释,双引号里面的内容可以根据个人的需要
![](https://img.haomeiwen.com/i3691899/7fa9ed441b21bc7e.png)
5)这里如果出现以下内容,则需要你输入自己的账号或名字
![](https://img.haomeiwen.com/i3691899/e59dbb91e4741ddd.png)
6)用上面提示的代码输入自己的邮箱或名字
![](https://img.haomeiwen.com/i3691899/f43431ca15edf545.png)
![](https://img.haomeiwen.com/i3691899/fbe53d088a555872.png)
7)再输入git commit -m "测试"时就会成功
![](https://img.haomeiwen.com/i3691899/30461790214bcace.png)
8)上传到github远程仓库
git remote add origin (你之前在github上复制的链接)git@github.com:test.git
git push -u origin master
![](https://img.haomeiwen.com/i3691899/32e14acacfa4c77e.png)
注意如果此处上传失败
出现错误的主要原因是github中的README.md文件不在本地代码目录中
![](https://img.haomeiwen.com/i1327716/3a006dc354a16173.jpg)
可以通过如下命令进行代码合并【注:pull=fetch+merge]
git pull --rebase origin master
![](https://img.haomeiwen.com/i1327716/6680511c6a422bad.jpg)
执行上面代码后可以看到本地代码库中多了README.md文件
![](https://img.haomeiwen.com/i1327716/bd399ac49fa6ad00.jpg)
![](https://img.haomeiwen.com/i1327716/fb717bdb56f28c52.jpg)
此时再执行语句 git push -u origin master即可完成代码上传到github
![](https://img.haomeiwen.com/i1327716/9303fdc6b4029b82.jpg)
![](https://img.haomeiwen.com/i3691899/f7391903ad619b51.png)
注意
1、Git提交代码发生LF will be replaced by CRLF in 问题
原因是需要提交的文件是在windows下生成的,windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时出现提示,解决办法:git config --global core.autocrlf false再执行git 提交
2、fatal: sha1 file '<stdout>' write error: Broken pipe
git push会出现一个问题:就是关于文件的大小!因为github的默认大小是100M,如果你的文件大于100M,那么你就不能成功,会出现这个:fatal: fatal: sha1 file '<stdout>' write error: Broken pipe The remote end hung up unexpectedly error
解决办法为:git config http.postBuffer 52428800 把大小配的大些即可