You created fix/cart-total, committed, and ran git push. Git stopped:
fatal: The current branch fix/cart-total has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin fix/cart-total
Nothing is broken. Git doesn’t know which remote branch your local branch belongs to, so it won’t guess.
Why it appears
A new local branch starts with no upstream: no remote branch it tracks. A plain git push needs one to know where to send the commits. A clone sets this up for main only, which is why main pushes fine and your new branch doesn’t.
Two quick checks. In this repository, git status -sb shows a branch with no upstream as a bare name:
git status -sb
## fix/cart-total
A tracked branch shows the remote branch, as in ## main...origin/main. For the exact setting, ask Git for the branch’s remote and merge target:
git config --get-regexp '^branch\.fix/cart-total\.'
No output means nothing is configured. A configured branch prints two lines:
branch.fix/cart-total.remote origin
branch.fix/cart-total.merge refs/heads/fix/cart-total
Push and set the upstream
Do both in one command. -u is short for --set-upstream:
git push -u origin HEAD
* [new branch] HEAD -> fix/cart-total
branch 'fix/cart-total' set up to track 'origin/fix/cart-total'.
origin is the remote and HEAD is the branch you are on, so you don’t retype its name. From now on, a plain git push and git pull work on this branch.
git push -u on its own does not work here: with Git’s default push.default=simple, it hits the same error. Name the remote.
The branch is already on the remote
If you pushed with git push origin fix/cart-total (no -u), the commits are on the server but the local branch still tracks nothing. A plain git pull then says There is no tracking information for the current branch. Link them without pushing again:
git branch --set-upstream-to=origin/fix/cart-total
branch 'fix/cart-total' set up to track 'origin/fix/cart-total'.
This needs origin/fix/cart-total to exist locally. Run git fetch origin first if the branch came from someone else.
Stop seeing the error
Tell Git to set the upstream for you on the first push of a branch:
git config --global push.autoSetupRemote true
After that, git push on a new branch pushes it and sets the upstream in one step:
* [new branch] fix/cart-total -> fix/cart-total
branch 'fix/cart-total' set up to track 'origin/fix/cart-total'.
The setting needs Git 2.37 or newer. It applies to every repository on your machine, so drop --global to try it in one repository first. It sends the branch to the remote it would push to anyway, so check the remote name if you work with forks.
When the upstream is set but Git can’t see it
In a clone made with --single-branch, only one branch is fetched. After git push -u origin HEAD on a new branch, the setting exists, but a command that reads the upstream, such as git log @{u}..HEAD, reports a broken one:
fatal: upstream branch 'refs/heads/fix/cart-total' not stored as a remote-tracking branch
git config --get branch.fix/cart-total.merge still prints refs/heads/fix/cart-total, so the upstream is set. What’s missing is a local copy of the remote branch. Tell the remote to fetch it, then fetch:
git remote set-branches --add origin fix/cart-total
git fetch origin
git status -sb now shows ## fix/cart-total...origin/fix/cart-total.
Other causes
- Detached HEAD.
You are not currently on a branchis a different error. Switch to a branch first:git switch -c fix/cart-total. src refspec ... does not match any. The branch you named has no commit to send. See Fix: src refspec does not match any.- A mistyped remote.
fatal: 'orign' does not appear to be a git repositorymeans the remote name is wrong. List the names withgit remote -v.
Catch unpushed branches before they pile up
A branch with no upstream is also one git status won’t flag as unpushed. Find unpushed commits shows how to list those across all your repositories, and stop accidental pushes to production covers the other side of a fast push. If git status says HEAD detached instead, save those commits on a branch before you push.
push& (Pushand) is a Mac menu bar app that watches your repositories and counts commits waiting to be pushed. For a new branch, Push creates the remote branch and asks first by default. Free for 3 repositories, and every install starts with a 14-day trial.