Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Git

Git: Fix a Stale Remote Branch That Still Shows Up After It Was Deleted Because fetch Never Pruned It

- 15.10.26 - ErcanOPAK

🔀 The Deleted Branch Nobody’s Clone Noticed

When a branch gets deleted on the remote – after a merge, during cleanup, however it happens – every clone that already has a local remote-tracking reference for it just keeps that reference around. A plain git fetch updates the branches that still exist; it doesn’t go out of its way to remove tracking references for ones that don’t, so origin/old-feature can sit in git branch -r for months after the branch itself is long gone.

🔎 The Problem

$ git fetch origin
# Fetches updates for branches that still exist on the
# remote - does nothing about ones that were deleted there.

$ git branch -r
  origin/main
  origin/feature-payments
  origin/old-feature       # deleted on the remote weeks ago,
                            # but still listed here locally.

$ git checkout old-feature
# Still works, still checks out a local tracking branch -
# nothing about this tells you the remote copy is gone.</pre>

✅ Fix: Prune Stale Tracking Refs Explicitly

  • Run git fetch --prune (or git fetch -p) to remove local remote-tracking references for branches that no longer exist on the remote – this only touches the tracking refs under refs/remotes/origin/*, it won’t touch any local branch you created yourself.
  • Set git config --global fetch.prune true once, and every future git fetch (and git pull, which calls fetch internally) prunes automatically – there’s rarely a good reason to keep stale remote-tracking refs around on purpose, so making this the default removes a recurring manual step.
  • git remote prune origin --dry-run shows exactly which tracking references would be removed before you commit to it – useful the first time you turn this on for an older clone that’s accumulated a long list of stale references over time.

⚠️ Why This Is Easy to Miss

  • A stale tracking reference doesn’t error or warn about anything – git branch -r and tab-completion both happily keep offering a branch name that hasn’t pointed at anything live on the remote in a long time.
  • It’s genuinely confusing in a team setting: one teammate’s clone has already pruned the reference and shows the branch as gone, while another’s hasn’t fetched with –prune recently and still sees it listed – both are looking at the same remote, just through differently stale local caches of it.

Deleting a branch on the remote doesn’t delete anyone’s memory of it – every clone keeps its own tracking reference until something actually tells it to clean up.

— Version Control Tip

Related posts:

Git: Fix git worktree list Showing a Worktree as Prunable Because Its Folder Was Moved Instead of Re...

Git: Fix git worktree list Showing a Worktree as Prunable Because Its Folder Was Moved Instead of Re...

Speed Up Large Repos with Partial Clones

Speed Up Large Repos with Partial Clones

Git: Find the Exact Commit that Broke Your Code with Bisect

Git: Find the Exact Commit that Broke Your Code with Bisect

Views: 15

Post navigation

JavaScript: Fix a Generator Function Return Value That Gets Silently Ignored Unless You Read It From the Final done Result
HTML5: Fix a Web Share API Call That Silently Fails Because It Wasn’t Triggered Directly by a User Gesture

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com