遇到问题
当我们在本地仓库关联远程github的时候可能会遇到如下问题,提供一些解决方法供大家选择解决问题,使得本地关联远程仓库成功
有如下几种解决方法:
1、push前先将远程repository修改pull下来
$ git pull origin master
$ git push -u origin master
2、使用强制push的方法:
$ git push -u origin master -f
这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。
3、若不想merge远程和本地修改,可以先创建新的分支:
$ git branch [name]
然后push
$ git push -u origin [name]
在解决问题中遇到的几个问题
1、git pull 提示refusing to merge unrelated histories
是因为两端在做完全不同的提交
解决方法:git pull --allow-unrelated-histories
2、git pull 报错:There is no tracking information for the current branch

是因为本地分支和远程分支没有建立联系 (使用git branch -vv 可以查看本地分支和远程分支的关联关系) .根据命令行提示只需要执行以下命令即可
解决方法:
一种是直接指定远程master:git pull origin master
另外一种方法就是先指定本地master到远程的master,然后再去pull:
git branch --set-upstream-to=origin/远程分支的名字 本地分支的名字
git pull
3、git push 报错GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.<br /> <br /> 是因为GitHub限制单个文件大小不能超过100M
解决方法:
a、初始化Git LFS,任何位置运行一次“git lfs init”进行初始化和安装git-lfs.
初始化成功后就可以用了. 如果没有安装好, 会显示:

可以通过使用 Homebrew 执行“brew install git-lfs”来安装,安装完成后,你还需要执行“git lfs install”命令
b、注册文件到LFS,例如要注册tar.gz文件, 可以git lfs track "*.tar.gz",此时将追踪相应文件后缀名符合的文件,要是想只是添加某些文件,指定文件就好了,追踪成功后会生成一个.gitattributes文件,里面有LFS管理的文件类型信息。<br /> <br />
c、随后就是一般的提交到github,git add ;git commit -m "comment";;git push origin master;所有修改都提交也可以。
d、 注:正常情况下,就能成功提交上去不报错了, 要是报错了,很有可能是你的大文件之前commit到本地库了,push时还是按之前的方式来提交到github所以报错;解决办法是撤销上一次commit后,进行再次push.