Skip to main content
DevOps Insightsguides & answers

Git · troubleshooting

fatal: The current branch has no upstream branch

The branch you are pushing was created locally and is not yet linked to a branch on the remote, so a plain git push does not know where to send it. Push it once with git push -u origin BRANCH, or set push.autoSetupRemote.

Reproduced on Git 2.50.1, . Where the text says “reproduced”, the behaviour was run on that version, not taken from documentation.

First published

New to this? Read what is actually happening first, then come back to the steps.

On this page · 8 sections

Before you start

  • A terminal in the repository, and push access to the remote.

Run this first

step 1 of 1
git branch -vv

Look for No [origin/…] for the current branch

Shows each local branch and the upstream it tracks, if any.

Work out which cause you have

A few questions to narrow the list. Every answer ends in a command that confirms or rules the cause out — this cannot see your cluster, so nothing here is a certainty until you have checked.

Narrow it down

0 answered · nothing is sent anywhere

Is this a branch you created locally and have not pushed before?

Cause space

2 of 2 still possible

  • A new local branch has never been pushedCommon
  • A script or CI job created the branch and runs a plain git pushOccasional

Nothing ruled out yet. Answer the question above and the branches your answer eliminates will strike through here.

Or diagnose it manually

In this order. The first command usually contains the whole answer.

  1. Step 1

    git branch -vv

    Shows each local branch and the upstream it tracks, if any.

    Look for No [origin/…] for the current branch

Every cause, and how to fix it

Ordered by how often each one turns out to be the answer.

A new local branch has never been pushed

Common

git switch -c or git checkout -b created the branch locally; nothing on the remote is linked to it yet.

Confirm

git branch -vv | grep '^\*'

The current branch with no [origin/…] in brackets

Fix

  • Push it once with tracking: git push -u origin BRANCH.
  • To make this automatic for every new branch: git config --global push.autoSetupRemote true.
git push -u origin HEAD

HEAD stands for the current branch, so you need not type its name. Checked on Git 2.50.1.

A script or CI job created the branch and runs a plain git push

Occasional

Release scripts and bots often run git checkout -b BRANCH, commit, then git push. In a fresh checkout no upstream exists, so the push fails the same way.

Confirm

grep -rn -E 'git (checkout -b|switch -c)' .github/ scripts/ 2>/dev/null

A branch created in the script followed by a plain git push

Fix

  • Name the destination in the script: git push origin HEAD (pushes the current branch under the same name), or git push -u origin HEAD if later steps pull.

Understanding it properly

Skip this if you are mid-incident — the working part of the page is above. Worth reading afterwards, because understanding the mechanism is what stops the next one.

In plain terms

A branch you create on your machine has no partner on the remote yet. git push with no arguments pushes to the branch's partner (its upstream), and there is none, so Git stops and prints the exact command to create it. You only need to do this once per branch.

Words used on this page

Upstream
The remote branch a local branch tracks; git push and git pull without arguments use it.
-u / --set-upstream
Pushes and records the remote branch as the upstream, so later pushes need no arguments.
What is actually happening

Reproduced on Git 2.50.1: git push on a newly created branch printed fatal: The current branch feature has no upstream branch, suggested git push --set-upstream origin feature, pointed to push.autoSetupRemote, and exited 128.

git push -u origin feature pushed it and set up tracking (branch 'feature' set up to track 'origin/feature'); later plain pushes and pulls then work.

With git config --global push.autoSetupRemote true, a plain git push on a new branch set up the upstream by itself.

How to tell this is your problem
WhereWhat you see
git pushfatal: The current branch BRANCH has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin BRANCH

How to know it is actually fixed

  • git branch -vv shows [origin/BRANCH] for the current branch.
  • A plain git push now succeeds.

Stopping it happening again

  • Set push.autoSetupRemote true once, globally.

Sources

Behaviour described here is drawn from official documentation. Where a figure could not be confirmed on an official page it is attributed in the text rather than stated as canonical.

Did this get you to an answer?

No text box on purpose — please do not paste production logs anywhere

Something wrong or out of date? Report it