创建项目时出现问题,大家看看我哪一步出错了
本地编写代码
github上创建新项目,并且用github直接 创建了readme.md
git remote add origin git@github.com:xxx/xxx
git push -u origin master
到这里,开始报错:
error: failed to push some refs to 'git@github.com:xxx'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
然后,git pull
,又报错:
warning: no common commits
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From github.com:xxx
+ 8324a8d...8c9fdd4 master -> origin/master (forced update)
fatal: refusing to merge unrelated histories
这到底哪里出错了?正确推送git项目的姿势是什么呀
阿神2017-06-26 10:51:31
你的第二次错误解决如下
[问题]fatal: refusing to merge unrelated histories
[解决]git pull origin master --allow-unrelated-histories
使用git的正确姿势是
1. git init
2.git add .
3.git commit -m '注释'
4. git remote add origin httpsxxxx
5.git pull origin master
6. git push -u origin master
高洛峰2017-06-26 10:51:31
通常来说,仓库只能有一个初始提交点,而你这里通过Github创建了一个初始提交,又在本地创建了一个初始提交,自然在本地进行推送的时候会报错。
如果你在Github创建项目的时候,选择了通过readme之类的方式初始化了仓库,你本地应该通过克隆远程仓库到本地,而不是创建一个新仓库并绑定远程仓库。
如果你在Github上创建项目的时候,没有选择仓库初始化选项,你可以在本地创建一个新仓库,并绑定远程仓库,把本地的初始提交推送到远程仓库。