說main/repo,當前的上游 repo有一個 branch newBranch。我有另一個myFork/repo沒有的那個 repo 的 forknewBranch
現在在本地,我想將它結帳upstream/newBranch到我的 PC,然后將其推送到origin/newBranch(這是我的叉子)。
我正在嘗試,git checkout upstream/newBranch但收到以下訊息:
Note: switching to 'upstream/newBranch'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
我希望我的本地分支跟蹤源分支,而不是上游分支
執行命令的正確順序是什么?謝謝
uj5u.com熱心網友回復:
這不是錯誤而是警告。此警告表示您處于分離的 HEAD 上。這意味著在推送時,沒有分支會跟隨您的提交,如果您不附加分支或將其合并到現有分支中,它將被 GC 收集。
您可以做的是創建一個與以下命令newBranch在同一點命名的分支upstream/newBranch:
git checkout -b newBranch upstream/newBranch
并且在推送時,必須指定推送的原點
git branch --set-upstream newBranch origin/newBranch
git push origin newBranch
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/361022.html
