Git Push Set Upstream: Fix "The Current Branch Has No Upstream Branch"
Fix "fatal: The current branch has no upstream branch" with git push -u, set tracking on an existing branch, and make Git set the upstream for you.
By PC MomentUpdated 5 min read

You created a new branch, made a commit, typed git push, and Git stopped with this:
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'.
Your branch exists only on your computer and isn’t linked to any branch on the remote yet. The fix is the command Git suggests: push once with --set-upstream (or its short form, -u), and plain git push works from then on.
What causes “the current branch has no upstream branch”
An upstream (or tracking) branch is the remote branch your local branch is linked to, such as origin/feature for your local feature. Git uses that link to know where an argument-less git push or git pull should go.
Branches you get by checking out a remote branch usually get an upstream automatically. A branch you create yourself with git switch -c or git checkout -b doesn’t have one until you set it.
Git’s default push behavior, push.default=simple, pushes the current branch to a branch with the same name on the remote, and in the usual setup (pushing to the same remote you pull from, typically origin) it needs an upstream configured. No upstream, no push, so Git stops and tells you how to set it.
How to fix it
Fix 1: Push with -u (set upstream while pushing)
This is the fix for almost everyone. Replace feature with your branch name:
git push -u origin feature
This pushes your branch to the remote called origin and, because of -u, records origin/feature as its upstream. You’ll see output like:
* [new branch] feature -> feature
branch 'feature' set up to track 'origin/feature'.
The long form does exactly the same thing:
git push --set-upstream origin feature
You only need -u once per branch. After that, just run:
git push
Tip: To avoid typing the branch name, use
HEAD, which means “the branch I’m on”:git push -u origin HEAD. The git manual describesgit push origin HEADas a handy way to push the current branch to the same name on the remote.
If the remote isn’t called origin, check its name first:
git remote -v
This lists each remote with its URL. Use that name instead of origin in the commands above.
Fix 2: Set the upstream on a branch that’s already on the remote
If the branch already exists on the remote (maybe you pushed it without -u, or a teammate created it), you can link your local branch without pushing:
git fetch origin
git branch --set-upstream-to=origin/feature
The first command makes sure your copy knows about the remote branch. The second sets origin/feature as the upstream of your current branch. The short form is git branch -u origin/feature. To set it for a different local branch, add its name at the end: git branch -u origin/feature feature.
If the remote branch doesn’t exist yet, Git refuses with:
fatal: the requested upstream branch 'origin/feature' does not exist
In that case, use Fix 1 to push the branch with -u instead.
Fix 3: Make Git set the upstream automatically
If you create a lot of short-lived branches, you can tell Git to set the upstream for you on the first push:
git config --global push.autoSetupRemote true
With this setting, when the current branch has no upstream, a plain git push behaves as if you had added --set-upstream. Per the git documentation, it takes effect when push.default is simple (the default since Git 2.0), upstream or current. It suits simple workflows where every branch has the same name on the remote. Current versions of Git point to it at the end of the error message.
Check which upstream each branch tracks
To see the upstream of every local branch:
git branch -vv
Example output:
* feature 568a62e [origin/feature] Add search box
main 1ae2a45 [origin/main: ahead 2] Fix footer links
test 5ea463a Try new layout
Here feature tracks origin/feature, main tracks origin/main and has two local commits that aren’t pushed, and test has no upstream at all. The ahead and behind numbers come from your last fetch, so run git fetch first if you want them up to date.
Change or remove an upstream
To point the current branch at a different remote branch:
git branch -u origin/other-branch
To remove the upstream from the current branch:
git branch --unset-upstream
If you link a branch to a remote branch with a different name, plain git push under the default simple setting refuses and suggests git push origin HEAD:<name> or git push origin HEAD. Keeping local and remote branch names the same avoids that.
Related errors
error: src refspec feature does not match any: the branch name in your push command doesn’t exist locally, or the branch has no commits yet. See error: src refspec main does not match any.fatal: not a git repository (or any of the parent directories): .git: you’re running the command outside your project folder. See fatal: not a git repository.! [rejected] ... (non-fast-forward)after you amended or rebased: your branch has an upstream, but its history changed. Read git push —force-with-lease before forcing anything.
If it still doesn’t work
- Run
git status. The first lines show your branch and, if it has one, its upstream and whether you’re ahead or behind. - Run
git remote -vto confirm the remote exists and points at the right URL. If there’s no remote at all, add one withgit remote add origin <url>. - If the push asks for credentials and fails, the upstream isn’t the problem; check your access to the remote repository with whoever manages it.
- If you’re unsure what a branch is tracking,
git branch -vvis the quickest answer.
For more Git walkthroughs, browse the programming guides, including how to undo the last commit in Git.
Frequently asked questions
What does git push -u do?
-u is short for --set-upstream. It pushes the branch and records the remote branch as its upstream, so later you can run plain git push and git pull without naming the remote and branch.
Do I need -u every time I push?
No. You only need it once per branch. After the upstream is set, plain git push works for that branch.
How do I see which upstream a branch is tracking?
Run git branch -vv. Each branch with an upstream shows it in square brackets, such as [origin/main], along with how far ahead or behind it is since your last fetch.
How do I make Git set the upstream automatically?
Run git config --global push.autoSetupRemote true. With the default push.default setting, Git then acts as if you passed --set-upstream whenever you push a branch that has no upstream yet.
Related guides

Programming
Error: src refspec main does not match any (and master): How to Fix It
Git can't push main or master because that branch doesn't exist locally yet. Make your first commit, match the branch name, and push again.
5 min read

Programming
Git Push --force-with-lease: The Safer Way to Force Push
What git push --force-with-lease does, how it differs from --force, when to use it after a rebase or amend, and why --force-if-includes makes it safer.
7 min read

Programming
Git Undo Last Commit: Reset, Revert, Amend and How to Get It Back
Undo your last Git commit the right way: keep the changes, throw them away, or reverse a commit you already pushed, plus how to recover from a bad reset.
7 min read

Programming
Fatal: Not a Git Repository: What It Means and How to Fix It
Git says "fatal: not a git repository" when it can't find a .git folder. Here's how to find the right folder, start a repository, and fix GIT_DIR, submodule and ownership problems.
6 min read