簡體   English   中英

Git: fatal: 當前分支 XXX 沒有上游分支(但它有上游分支)

[英]Git: fatal:The current branch XXX has no upstream branch (but it HAS the upstream branch)

我們使用 git + Jira + Bitbucket。

設想:

  1. 在 Jira 中,我創建了(使用Create branch選項)分支XXX

  2. 在 Bitbucket 中,我看到分支XXX出現在分支列表中。

  3. 在代碼中進行更改 => git commit

  4. git push給出: fatal: The current branch XXX has no upstream branch.

問題:這個錯誤的原因是什么? 分支XXX上游分支(我在 Jira 中看到這個上游分支XXX 。)

請注意:在出現此錯誤之前,我使用了沒有附加參數的git push

UPD0:@RadioSilence 建議使用git branch -vv命令。 我做到了,它幫助我看到“本地分支機構沒有跟蹤上游”。 原因(很可能)是我之前在該分支上的一些 git 命令,這顯然導致該分支禁用了對上游的跟蹤。 (默認情況下,在簽出使用 Jira 創建的任何分支后,該分支跟蹤上游,因此git push不需要額外的命令/選項。)

結果(解決方案):

  1. 我已將導致問題的分支名稱從XXX更改為XXX_01

  2. git checkout XXX => 添加更改(通過git stash apply stash@{0} )=> git commit

  3. git push (沒有額外的命令/選項)並且它按預期工作。

PS 如果有人知道如何無意中禁用分支(使用 Jira 創建)對上游的跟蹤,請告訴我們。

正如評論中提到的,本地分支沒有跟蹤上游。 這可以通過運行git branch -vv來驗證。 如果本地分支沒有列出上游,則運行git push -u origin XXX

如果您使用 sourcetree 作為界面將更改推送到 bitbucket 服務器,請單擊終端按鈕。 然后使用需要推送更改的遠程分支名稱運行以下命令。 git branch --set-upstream <remote-branch>

在cmd下面執行:

git branch -M main
git push -u origin main

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM