Updates were rejected because the tip of your current branch is behind

作者: xahy 分类: Git 发布时间: 2019-08-21 00:15

我在写自己的小玩意儿的时候习惯了使用码云(gitee.com)平台来存储代码,

有的时候在本地写好了一部分代码,

需要上传到平台的时候发现忘了创建仓库,

就得去平台上创建一个仓库,

但是码云上给出的操作流程并不如想github那样清晰,

Updates were rejected because the tip of your current branch is behind

Updates were rejected because the tip of your current branch is behind

还得自己去敲命令这样就容易出错。

 

像上面图片给出的就是在github创建一个仓库后,

会给出是新建目录还是已有目录上传代码对应的git命令,

因为习惯了使用 码云不是,

没有也得接着用。

 

由于我是一般写好了代码,

然后再上传到仓库上,

所以我肯定是 git init git remote add 一类的命令。

具体的操作流程,

理想的应该是

cd test
git init
git remote add origin git@gitee.com:xianhenyuan/test.git
git add .
git commit -m "ok"
git pull origin master
git push -u origin master

ps:由于需要拉取码云平台的README文件所以上面多了一步git pull。

 

然鹅,

在push 的时候会直接返回以下错误

To gitee.com:xianhenyuan/test.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@gitee.com:xianhenyuan/test.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.

提示落后远程分支,

但是本地 pull 的话一直没反应,

很是顽皮!

 

温柔的不行,

就得强悍一点了!

这个时候就需要在后面加上 --allow-unrelated-histories

命令就是这个样子:git pull origin master --allow-unrelated-histories

然后重新:git push -u origin master 即可ok。

$ git push -u origin master
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 3.40 KiB | 3.40 MiB/s, done.
Total 7 (delta 1), reused 0 (delta 0)
remote: Powered By Gitee.com
To gitee.com:xianhenyuan/test.git
62c93f4..106c91c master -> master
Branch ‘master’ set up to track remote branch ‘master’ from ‘origin’.

备注:

请各位看官注意,非相同场景,请谨慎尝试!

发表评论

电子邮件地址不会被公开。 必填项已用*标注