Git錯誤,Updates were rejected because the tip of your current branch is behind


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

在push代碼時,遇到這種問題Updates were rejected because the tip of your current branch is behind
(更新被拒絕,因為當前分支的尖端落后)

解決

有三種方案

  1. push前先將遠程repository修改pull下來
git pull origin master
git push -u origin master
  1. 使用強制push的方法:
git push -u origin master -f 

這樣會使遠程修改丟失,一般是不可取的,尤其是多人協作開發的時候。

  1. 若不想merge遠程和本地修改,可以先創建新的分支:
git branch [name]
#然后push
git push -u origin [name]

衍生問題

使用上述方法在pull時可能會遇到如下問題
1.git pull 提示refusing to merge unrelated histories
這個有解決辦法

2.There is no tracking information for the current branch(沒有當前分支的跟蹤信息)
是因為本地分支和遠程分支沒有建立聯系
(使用git branch -vv 可以查看本地分支和遠程分支的關聯關系,查看遠程分支 git remote -v)
解決方法:
1)是直接指定遠程master:

git pull origin master

​2)另外一種方法就是先指定本地master到遠程的master,然后再去pull:

git branch --set-upstream-to=origin/遠程分支的名字  本地分支的名字
git pull

關於git remote可以看看這篇文章


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM