Git錯誤,Updates were rejected because the tip of your current branch is behind
阿新 • • 發佈:2020-10-20
問題: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
(更新被拒絕,因為當前分支的尖端落後)
解決
有三種方案
- push前先將遠端repository修改pull下來
git pull origin master
git push -u origin master
- 使用強制push的方法:
git push -u origin master -f
這樣會使遠端修改丟失,一般是不可取的,尤其是多人協作開發的時候。
- 若不想merge遠端和本地修改,可以先建立新的分支:
git branch [name]
然後push
git push -u origin [name]
衍生問題
使用上述方法在pull時可能會遇到如下問題
-
git pull 提示refusing to merge unrelated histories
這個有解決辦法 -
There is no tracking information for the current branch(沒有當前分支的跟蹤資訊)
是因為本地分支和遠端分支沒有建立聯絡
(使用git branch -vv
解決方法:
1)是直接指定遠端master:
git pull origin master
2)另外一種方法就是先指定本地master到遠端的master,然後再去pull:
git branch --set-upstream-to=origin/遠端分支的名字 本地分支的名字
git pull
關於git remote可以看看這篇文章