How to fix error: the requested upstream branch 'origin/feature' does not exist in Git

GitBEGINNERLOWUpdated Dec 6, 2025ยท 225 views

This Git error occurs when trying to set an upstream branch that your local repository doesn't know about. The fix is usually to run 'git fetch' first to update your local knowledge of remote branches, or use 'git push -u' to create and track the branch in one step.

Quick fix

Fixes error: the requested upstream branch 'origin/feature' does not exist

# Fetch from origin (most common remote name)
git fetch origin

# If using a different remote name (e.g., upstream for forked repos)
git fetch upstream

# Fetch from all remotes
git fetch --all
  1. Fetch from the correct remote
  2. Verify the remote branch exists
  3. Use git push -u to create and track in one step
  4. Check your remote configuration
git โ€” error
# Fetch from origin (most common remote name)
git fetch origin
# If using a different remote name (e.g., upstream for forked repos)
git fetch upstream
# Fetch from all remotes
git fetch --all
error: the requested upstream branch 'origin/feature' does not exist

What this error means

This error appears when you run `git branch --set-upstream-to=origin/<branch>` but the specified remote tracking branch doesn't exist in your local repository's knowledge of the remote. Git can only set upstream tracking to branches it knows about. Your local Git maintains a cached view of remote branches (stored as references like `origin/main`, `origin/feature`, etc.). These references are updated when you run `git fetch`. If a branch exists on the remote but you haven't fetched recently, or if the branch doesn't exist on the remote at all, you'll see this error. The key insight is that `--set-upstream-to` requires the remote tracking branch to already exist locally. It doesn't reach out to the remote to check - it only looks at what Git already knows about.

Typical symptoms

  • Running 'git branch --set-upstream-to=origin/<branch>' fails with 'does not exist' error
  • Git suggests running 'git fetch' but a plain 'git fetch' doesn't fix the issue
  • Unable to push with 'git push -u' because the branch doesn't exist remotely
  • 'git branch -r' doesn't show the expected remote branch
  • Recently cloned repository missing remote branch references
  • Working on a new local branch that hasn't been pushed yet
  • Trying to track a branch from a secondary remote that hasn't been fetched

Common causes

  1. Haven't run 'git fetch' to update knowledge of remote branches
  2. The branch doesn't exist on the remote repository yet
  3. Running 'git fetch' without specifying the correct remote name
  4. Typo in the branch name or remote name
  5. The branch was deleted from the remote repository
  6. Shallow clone missing branch references
  7. Missing or incorrect fetch configuration in .git/config
  8. Using 'upstream' instead of 'origin' or vice versa

How to fix "error: the requested upstream branch 'origin/feature' does not exist"

1Fetch from the correct remote

The most common fix is to fetch from the remote to update your local branch references:

bash
# Fetch from origin (most common remote name)
git fetch origin

# If using a different remote name (e.g., upstream for forked repos)
git fetch upstream

# Fetch from all remotes
git fetch --all

After fetching, try setting the upstream again:

bash
git branch --set-upstream-to=origin/feature

Note: Running just git fetch without a remote name uses the default remote, which might not be the one you need.

2Verify the remote branch exists

Check what remote branches your local Git knows about:

bash
# List all remote branches
git branch -r

# List all branches (local and remote)
git branch -a

# Check if a specific branch exists
git branch -r | grep feature

If the branch isn't listed, it either:
1. Doesn't exist on the remote (needs to be pushed)
2. Hasn't been fetched yet (run git fetch)

Check directly on the remote:

bash
# See what branches exist on the remote without fetching
git ls-remote --heads origin
3Use git push -u to create and track in one step

If the branch doesn't exist on the remote yet (it's a new local branch), use git push -u to push and set up tracking simultaneously:

bash
# Push the current branch and set upstream tracking
git push -u origin feature

# Or for the current branch (whatever it's named)
git push -u origin HEAD

The -u (or --set-upstream) flag:
1. Pushes the branch to the remote
2. Creates the remote tracking branch (origin/feature)
3. Sets up your local branch to track it

After this, future git push and git pull commands will work without specifying the remote and branch.

4Check your remote configuration

Verify that your remote is configured correctly:

bash
# List all remotes
git remote -v

# Check fetch configuration for origin
git config --get remote.origin.fetch
# Should return: +refs/heads/*:refs/remotes/origin/*

If the fetch configuration is missing or incorrect, fix it:

bash
# Set the correct fetch configuration
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

Check your .git/config file:

ini
[remote "origin"]
    url = https://github.com/user/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

If the fetch line is missing, that's why git fetch isn't working properly.

5Handle shallow clones

If you did a shallow clone, you might be missing branch information:

bash
# Check if you have a shallow clone
git rev-parse --is-shallow-repository
# Returns "true" if shallow

# Unshallow to get full history and all branches
git fetch --unshallow

# Or fetch specific branch depth
git fetch --depth=100 origin feature

For CI/CD pipelines, ensure your clone command includes branch information:

bash
# Instead of shallow clone
git clone --depth 1 https://github.com/user/repo.git

# Use this to include branches
git clone --depth 1 --no-single-branch https://github.com/user/repo.git
6Verify remote name and branch name

Double-check that you're using the correct names:

bash
# List all remotes
git remote -v
# origin    https://github.com/user/repo.git (fetch)
# origin    https://github.com/user/repo.git (push)
# upstream  https://github.com/original/repo.git (fetch)

# List remote branches to see exact names
git branch -r
# origin/main
# origin/develop
# upstream/main

Common mistakes:
- Using upstream when you meant origin
- Branch name case sensitivity (Feature vs feature)
- Missing remote prefix (using feature instead of origin/feature)

bash
# Correct format
git branch --set-upstream-to=origin/feature

# NOT (missing origin/)
git branch --set-upstream-to=feature

Advanced notes

### Understanding Remote Tracking Branches

Remote tracking branches (like origin/main) are local references that track the state of branches on remote repositories. They're read-only snapshots updated by git fetch.

bash
Local branches:         Remote tracking branches:    Remote branches:
main                    origin/main        <-->      main (on GitHub)
feature           -->   origin/feature     <-->      feature (on GitHub)

### The Difference Between Remote Names

- origin: Default name for the primary remote (where you cloned from)
- upstream: Conventionally used for the original repo when working with forks

bash
# Typical fork setup
git remote add upstream https://github.com/original/repo.git
git fetch upstream
git branch --set-upstream-to=upstream/main

### Prune Stale Remote Tracking Branches

If a branch was deleted from the remote, your local remote tracking branch might still exist:

bash
# Remove stale remote tracking branches
git fetch --prune origin

# Or enable auto-pruning
git config --global fetch.prune true

### Setting Upstream for New Branches Automatically

Configure Git to automatically set up tracking for new branches:

bash
# When pushing a new branch, automatically set upstream
git config --global push.autoSetupRemote true

With this setting, git push on a new branch works without -u.

### Checking Current Upstream Configuration

bash
# Show upstream for current branch
git rev-parse --abbrev-ref --symbolic-full-name @{u}

# Show upstream for all branches
git branch -vv
# * feature  abc1234 [origin/feature] Latest commit message
#   main     def5678 [origin/main] Another commit

### Single-Branch Clones

If you cloned with --single-branch, only one branch is tracked:

bash
# See current fetch refspec
git config --get remote.origin.fetch

# Allow fetching all branches
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

Frequently asked questions

What does "error: the requested upstream branch 'origin/feature' does not exist" mean?
This error appears when you run git branch --set-upstream-to=origin/<branch> but the specified remote tracking branch doesn't exist in your local repository's knowledge of the remote. Git can only set upstream tracking to branches it knows about. ).
How do I fix "error: the requested upstream branch 'origin/feature' does not exist"?
This Git error occurs when trying to set an upstream branch that your local repository doesn't know about. The fix is usually to run 'git fetch' first to update your local knowledge of remote branches, or use 'git push -u' to create and track the branch in one step.
What causes "error: the requested upstream branch 'origin/feature' does not exist"?
Haven't run 'git fetch' to update knowledge of remote branches The branch doesn't exist on the remote repository yet Running 'git fetch' without specifying the correct remote name
Is the "error: the requested upstream branch 'origin/feature' does not exist" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading