push到github报错解决方法

本文介绍在使用Git过程中遇到的推送失败问题及解决方法,包括强制推送、先拉取再推送及创建新分支等策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在push代码到远程仓库时,报了如下的错误:

$ git push -u origin master
To https://github.com/11pdg/group-buy.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/11pdg/group-buy.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.

查阅资料得知,是因为在github上创建仓库的时候,顺便也创建了README文件,然而本地仓库又没有这个文件,所以导致版本冲突。

有以下几种解决方法:

1、强制push到远程仓库:

git push -u origin master -f

但是这样会导致远程仓库里的东西丢失,一般不会采用这样的方法,特别是团队开发的时候。

2、push前先将远程仓库pull下来,再进行push:

git pull origin master
git push -u origin msater

3、创建新的分支:

git branch [name]

git push -u origin [name]

 

转载于:https://www.cnblogs.com/11lang/p/6130927.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值