Skip to content

/errors/git/current-branch-has-no-upstream-branch

fatal: The current branch has no upstream branch

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated
tool
Git
exit code
128
versions
Git 2.x, push.autoSetupRemote: Git 2.37+
os
linux, macos, windows

fatal: The current branch X has no upstream branch. means git push without arguments does not know where to push, because the local branch X has no upstream (remote-tracking) branch yet. That is normal for a branch you just created. Push it once with git push -u origin X; -u stores the upstream, so later git push and git pull work without arguments.

Reproduce it

bash
git init -q --bare origin.git
git clone -q origin.git work 2>/dev/null && cd work
git switch -q -c main && echo a > a && git add a && git commit -qm init && git push -q -u origin main
git switch -q -c feature && echo b > b && git add b && git commit -qm feature
git push

Output · exit 128

fatal: The current branch feature has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin feature

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

Git's message already contains the fix and mentions the setting that automates it.

Fix: push with -u once

bash
git init -q --bare origin.git
git clone -q origin.git work 2>/dev/null && cd work
git switch -q -c feature && echo b > b && git add b && git commit -qm feature
git push -q -u origin feature
git status -sb | head -n 1
git rev-parse --abbrev-ref feature@{upstream}

Output

## feature...origin/feature
origin/feature

Make it automatic

bash
git init -q --bare origin.git
git clone -q origin.git work 2>/dev/null && cd work
git config push.autoSetupRemote true
git switch -q -c feature && echo b > b && git add b && git commit -qm feature
git push -q
git rev-parse --abbrev-ref feature@{upstream}

Output

origin/feature

Set it for all repositories with git config --global push.autoSetupRemote true (Git 2.37+). With it, the first plain git push of a new branch behaves like git push -u origin BRANCH.

CommandPushesSets upstream
git push -u origin featurefeature to origin/featureyes
git push origin HEADcurrent branch to the same nameno
git push origin featurefeature to origin/featureno
git push (with push.autoSetupRemote)current branch to the same nameyes, on the first push

Sources