简体   繁体   English

Git: fatal: 当前分支 XXX 没有上游分支(但它有上游分支)

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

We use git + Jira + Bitbucket.我们使用 git + Jira + Bitbucket。

Scenario:设想:

  1. In Jira I've created (with Create branch option) branch XXX .在 Jira 中,我创建了(使用Create branch选项)分支XXX

  2. In Bitbucket I see that the branch XXX is appeared in the list of branches.在 Bitbucket 中,我看到分支XXX出现在分支列表中。

  3. Make changes in the code => git commit .在代码中进行更改 => git commit

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

Question: what is the reason of this error?问题:这个错误的原因是什么? The branch XXX has the upstream branch (I see this upstream branch XXX in the Jira.)分支XXX上游分支(我在 Jira 中看到这个上游分支XXX 。)

Please note: before this error I've used git push with NO additional arguments.请注意:在出现此错误之前,我使用了没有附加参数的git push

UPD0: @RadioSilence has suggested to use git branch -vv command. UPD0:@RadioSilence 建议使用git branch -vv命令。 I did and it helped me to see that "the local branch is not tracking the upstream".我做到了,它帮助我看到“本地分支机构没有跟踪上游”。 And the reason of it was (very probably) some of my previous git commands on that branch, which apparently caused disabling the tracking of the upstream by this branch.原因(很可能)是我之前在该分支上的一些 git 命令,这显然导致该分支禁用了对上游的跟踪。 (By default after checking out any branch created with Jira the branch is tracking the upstream, hence NO additional commands/options are needed for git push .) (默认情况下,在签出使用 Jira 创建的任何分支后,该分支跟踪上游,因此git push不需要额外的命令/选项。)

As a result (solution):结果(解决方案):

  1. I've changed the name of the branch caused the issue from XXX to XXX_01 .我已将导致问题的分支名称从XXX更改为XXX_01

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

  3. git push (with NO additional commands/options) and it worked as expected. git push (没有额外的命令/选项)并且它按预期工作。

PS If anyone knows how it was possible to unintentionally disable the tracking of the upstream by the branch (created with Jira), please let us know. PS 如果有人知道如何无意中禁用分支(使用 Jira 创建)对上游的跟踪,请告诉我们。

As mentioned in the comments, the local branch is not tracking the upstream.正如评论中提到的,本地分支没有跟踪上游。 This can be verified by running git branch -vv .这可以通过运行git branch -vv来验证。 If the local branch has no listed upstream, then run git push -u origin XXX .如果本地分支没有列出上游,则运行git push -u origin XXX

If you are using sourcetree as your interface to push your changes to bitbucket server, click on terminal button.如果您使用 sourcetree 作为界面将更改推送到 bitbucket 服务器,请单击终端按钮。 Then run the following command with the remote-branch name to which the changes needs to be pushed.然后使用需要推送更改的远程分支名称运行以下命令。 git branch --set-upstream <remote-branch>

execute below cmd:在cmd下面执行:

git branch -M main
git push -u origin main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM