我正在這個本地分支 X 上作業,當我嘗試使用git push -u origin X
錯誤訊息進行推送時:
! [rejected] X -> X (non-fast-forward)
error: failed to push some refs to "********"
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.
所以我運行:git pull
并且還會出現一條錯誤訊息:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> X
uj5u.com熱心網友回復:
您有一個名為 的本地分支X,沒有跟蹤資訊,因此沒有對應的upstream。
然后你試圖把它推到originas X。到目前為止一切都很好......但是在那個遙控器中有一個具有該名稱的分支,因此只有在快進時才會接受您的推送,而事實并非如此。
當您git pull嘗試合并/重新定位跟蹤分支時,但您X沒有!所以它失敗了。
您基本上有兩種選擇:
- 添加跟蹤資訊:正如 git 在控制臺中幫助列印的那樣:
git branch --setup-upstream-to=origin/X X, 然后git pull,git status,git merge,git rebse,git push不帶引數將默認為跟蹤分支,它將按預期作業。 - 請拒絕添加跟蹤資訊。然后您必須執行完整的命令:
git fetch origin, thengit rebase origin/Xorgit merge origin/X, andgit push origin X。
由于您正在嘗試git push -u, 并且-u意味著“添加跟蹤資訊”,我猜您需要選項 1。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/360187.html
