Search code examples
gitpushbranch

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


We use git + Jira + Bitbucket.

Scenario:

  1. In Jira I've created (with Create branch option) branch XXX.

  2. In Bitbucket I see that the branch XXX is appeared in the list of branches.

  3. Make changes in the code => git commit.

  4. git push gives: 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.)

Please note: before this error I've used git push with NO additional arguments.

UPD0: @RadioSilence has suggested to use git branch -vv command! 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. (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.)

As a result (solution):

  1. I've changed the name of the branch caused the issue from XXX to XXX_01.

  2. git checkout XXX => add changes (via git stash apply stash@{0}) => git commit.

  3. git push (with NO additional commands/options) and it worked as expected.

P.S. 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.


Solution

  • As mentioned in the comments, the local branch is not tracking the upstream. This can be verified by running git branch -vv. If the local branch has no listed upstream, then run git push -u origin XXX.