本地项目推送至gitee.com看了很多资料,最后算是完成了
开始步骤:
第一步:首先在gitee.com上创建一个项目,与你本地项目同名(如何创建不在此讲解)
第二步:在git bash 下操作
① git init 初始化本地仓库
② git add . 将当前文件加入到仓库
③ git commit -m 'first commit' 第一次提交项目文件
④ git remote add origin https://gitee.com/null_948_8938/ayiol_auth.git 关联远程仓库,蓝色为git项目URL
⑤ git push -u origin master 推送远程仓库
执行第五步时报错如下:
error: failed to push some refs to 'https://gitee.com/null_948_8938/ayiol_auth.git'
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拉下远程代码到本地
git pull
warning: no common commits
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://gitee.com/null_948_8938/ayiol_auth
* [new branch] master -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
报错原因是没有指定本地master和远程origin/master的连接,执行git branch --set-upstream master origin/master,设置链接
git branch --set-upstream master origin/master
fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.
再次执行:git pull origin master
fatal: refusing to merge unrelated histories 拒绝合并不相关的历史
报错原因是本地仓库与远程仓库不同
解决方案:
git添加一句代码,这句代码是在git2.9.2版本发生的,最新版本需要添加 --allow-unrelated-histories,此代码为忽略不相关历史文件
即:git pull origin master --allow-unrelated-histories
重新git push origin master ,不在报错,推送完成