git推送代码去新建并初始化的远程仓库报错

当在GitHub上新建并初始化了一个带有README的仓库,尝试将本地项目推送到该仓库时,由于两边都有初始内容,导致推送失败。解决办法是在git提示合并分支的编辑框中输入“:wq”退出编辑,然后正常推送。
$ git push -u origin master
To https://gitee.com/****/spring-cloud-*****-study.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/****/spring-cloud-****-study.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

git推送本地代码去新创建的远程仓库失败。

原因

在创建仓库的时候勾选了“使用Reamdme文件初始化这个仓库”。它会帮我们做一次初始提交,然后仓库就生成了README.m和.gitignore文件。当我们把本地项目关联到这个仓库把项目推送到仓库时,两端都是有内容的,但是这两份内容并没有联系。所以当我们推送到远程或者从远程拉取内容时,都会提示是没有被跟踪的内容,git报的提示中会让你先拉取再推送,但是拉取总是失败。

解决方法

git fetch origin

git merge origin/master  //如果提示fatal: refusing to merge unrelated his
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值