本地项目推送至git --亲自操作后的总结

本地项目推送至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 ,不在报错,推送完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值