What just happened
You created a new local branch, ran git push, and got slapped with this:
fatal: The current branch feature/my-branch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin feature/my-branch
Your branch is brand new โ never pushed before. Git has no idea which remote branch it should talk to. Branches like main or master usually come pre-wired to a remote, but any branch you create locally starts with zero upstream mapping until you set one.
Quick fix
Git already told you the answer. Run it:
git push --set-upstream origin feature/my-branch
Or the shorter version most people use day-to-day:
git push -u origin feature/my-branch
Both do the same thing. Your branch gets pushed to origin, and Git remembers that mapping. Every subsequent git push or git pull on this branch will just work โ no extra flags.
Don't want to type the branch name?
Use HEAD instead:
git push -u origin HEAD
HEAD always points to whatever branch you have checked out. Works regardless of what you named it โ handy when your branch name is something like fix/PROJ-2847-auth-token-expiry.
Verify the fix worked
Run this after pushing:
git branch -vv
Look for the remote tracking reference in brackets:
* feature/my-branch a1b2c3d [origin/feature/my-branch] Your commit message
No brackets? The upstream still isn't set. You can double-check with git status too โ a properly tracked branch shows something like "Your branch is up to date with 'origin/feature/my-branch'".
Never type -u again โ the permanent fix
If you push new branches multiple times a week, this gets old fast. One global config option eliminates the problem entirely:
git config --global push.autoSetupRemote true
From that point on, a plain git push on any new branch automatically pushes it and sets the upstream. No flags. No friction. Note that this requires Git 2.37 or newer โ released July 2022.
Check your version first:
git --version
Running something older? Fall back to this instead:
git config --global push.default current
It pushes to a remote branch with the same name as your local one. The catch: it doesn't record the upstream tracking reference. You still need -u once to enable git pull without arguments. But at least the push itself won't blow up.
When you have multiple remotes
Working with a fork? You probably have two remotes โ origin (your fork) and upstream (the original repo). Be explicit about which one you're pushing to:
# See what remotes you have
git remote -v
# Push to your fork
git push -u origin feature/my-branch
# Push to the upstream repo (if you have write access)
git push -u upstream feature/my-branch
Link without pushing
Sometimes a remote branch already exists โ a teammate created it, or you're picking up someone else's work. No need to push anything. Just link your local branch to it:
git branch --set-upstream-to=origin/feature/my-branch
Short flag version:
git branch -u origin/feature/my-branch
After a git fetch, this lets you track that remote branch without creating an extra commit or push.
Summary
- New local branches have no upstream โ Git won't push them blindly.
- One-time fix:
git push -u origin HEAD - Permanent fix (Git 2.37+):
git config --global push.autoSetupRemote true - Verify with:
git branch -vv

