Git 报错:Updates were rejected because the tip of your current branch is behind

2023-05-25,,

  刚开始学习 git 命令,发现会出现很多的错误,所以就总结下出现的错误,以此来加深理解和掌握吧!

环境:在本地库操作了一系列的 add 和 commit 操作后,想把本地仓库推送到远端,但是发生以下错误:

错误情况:Updates were rejected because the tip of your current branch is behind

错误原因:我在远端 github 的版本库创建页面点击创建 README.md 按钮创建了说明文档,但是没有 pull 到本地,这样就产生了版本冲突问题。

解决方法:

1,使用强制 push 的方法:

# 该方法会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候
$ git push -u origin master -f

2,push 前先将远程 repo 修改 pull 下来

# 先 pull 下来,在次进行推送到远端
$ git pull origin master
$ git push -u origin master

Git 报错:Updates were rejected because the tip of your current branch is behind的相关教程结束。

《Git 报错:Updates were rejected because the tip of your current branch is behind.doc》

下载本文的Word格式文档,以方便收藏与打印。