git第一次推送出现推送被拒绝

前言

git 第一次推送出现以下错误

! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘https://gitee.com/fengshangyunwang/iot-front-end.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.


一、解决方案

这个错误提示说明你未能成功推送代码到远程仓库,因为远程仓库中存在你没有本地副本的分支,或者你未能解决与远程仓库中已有分支的冲突。为了解决这个问题,你可以使用以下命令

1.git pull:该命令将会获取远程仓库最新的代码,并且尝试自动合并到当前分支。如果存在冲突,需要手动解决之后再次提交。

git pull origin master

2.git fetch:该命令将会获取远程仓库最新的代码更新,但不会自动合并到当前分支,需要手动进行合并。

git fetch origin master
git merge origin/master

3.强制推送:如果你确信本地分支是正确的,可以使用强制推送来覆盖远程仓库中的分支,使用后,请确保你知道这样做的后果。

git push -f origin master
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值