将本地代码提交到github

最近练习了freemarker 做了个代码生成工具,想提交到github上,在本地进行了提交,执行如下些命令

git init

git add . *

git commit -m "commit"。

之后在github账户中创建了新的repository(参考 http://blog.csdn.net/hanhailong726188/article/details/46738929 ),起名和本地项目名称一致叫freemarker。

开始执行上传代码操作如下:

1. git remote add origin https://github.com/baixiaodong/freemarker.git  显示正常

执行 2. git pull origin master  提示错误 fatal: refusing to merge unrelated historie  如下图:

看意思是不相关拒绝合并。奇怪,明明已经执行关联了呀。 于是重新执行了 git remote add origin ,提示fatal: remote origin already exists。 

于是先执行了git remote rm origin。

再重新执行如上红色字的 1、 2 两步,第二步执行还是同样的错误。查找资料提示说 是因为不同仓库的原因,如果要合并需要在pull是加参数为:--allow-unrelated-histories

再执行 git pull origin master  --allow-unrelated-histories, 终于进入了合并界面 。

附图:

最后执行,提示成功

再看github上,已经提交成功了

原文地址:https://www.cnblogs.com/blacksonny/p/6920933.html