git
remote branch
error troubleshooting
branch deletion
version control

Git says remote ref does not exist when I delete remote branch

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

When Git says a remote ref does not exist during branch deletion, it usually means the branch name you are trying to delete is not present on the remote under that exact reference. The cause is often simple: the branch was already deleted, the name is wrong, or you are deleting the wrong remote.

This is one of those Git errors that sounds mysterious but becomes obvious once you inspect the actual remote refs. The fix is usually verification, not force.

A good mental model is that Git is not refusing to delete the branch. It is telling you that the named ref is not present on the remote, so there is nothing for the deletion command to remove.

The Correct Deletion Command

The normal way to delete a remote branch is:

bash
git push origin --delete feature/login-cleanup

This asks the remote named origin to delete the branch ref feature/login-cleanup.

If Git replies that the remote ref does not exist, the first question is whether that branch really exists on origin under that exact name.

Verify the Remote Branch Name

Use git ls-remote to check what the remote actually has:

bash
git ls-remote --heads origin

Or narrow it to one branch:

bash
git ls-remote --heads origin feature/login-cleanup

If nothing is returned, the remote does not currently have that branch ref. At that point, the error is accurate: there is nothing there to delete.

Update Your Local Remote-Tracking State

Sometimes your local clone still shows an old remote-tracking branch even though the remote branch is already gone. Refresh that state with:

bash
git fetch origin --prune

After pruning, check again:

bash
git branch -r

If origin/feature/login-cleanup disappears after pruning, the branch had already been removed remotely and your local view was just stale.

Common Causes

Typical reasons for this error are:

  • the branch was already deleted by someone else,
  • the branch name is misspelled,
  • you are targeting the wrong remote,
  • the remote branch was renamed,
  • the local remote-tracking refs were stale.

Case sensitivity can matter too. A remote branch named Feature/Login-Cleanup is not the same ref as feature/login-cleanup on case-sensitive systems.

This shows up often after branch renames done through a hosting UI. Your local clone may still remember the old remote-tracking name until you fetch and prune.

Old Syntax Versus New Syntax

You may still see the older deletion syntax:

bash
git push origin :feature/login-cleanup

It works, but git push origin --delete branch-name is easier to read and less error-prone. If either command reports the ref does not exist, the diagnosis is still the same: Git cannot find that branch on the remote.

Common Pitfalls

  • Deleting the branch from the wrong remote.
  • Trusting stale origin/... entries locally instead of checking the remote directly.
  • Copying the wrong branch name from a UI or ticket.
  • Assuming the remote branch exists because a local branch with the same name exists.
  • Using forceful commands when the real issue is simply that the branch is already gone.

Summary

  • 'remote ref does not exist usually means the branch is not on that remote under that exact name.'
  • Use git ls-remote --heads origin to verify the remote branch directly.
  • Run git fetch --prune to clean stale remote-tracking refs.
  • Confirm the remote name and branch spelling before retrying.
  • Most of the time, the branch has already been deleted or the name is slightly wrong.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.