Git Clean Up Remote Branches | Remove Stale Branches with Git Prune
Your team merges features, fixes bugs, and ships releases. But what happens to the branches afterwards? They stay there — and the list you read every day keeps growing.
Two things trip people up:
merged does not mean deleted from the remote
deleted on the remote does not mean removed from your clone
That second one is the real source of clutter. A remote-tracking reference like origin/feature/payment is your clone's own copy of what origin had last time you looked. When a teammate deletes the branch on GitHub, your copy of that reference stays until you clean it up.
This 2-minute explainer shows how, with a Ruby on Rails payment-api example.
What you'll learn:
- Why remote branch lists get cluttered
- What a remote-tracking branch actually is
- How pruning works, step by step
- How to clean up stale references
- The difference between local branches, remote branches, and remote-tracking references
- When to use git fetch --prune vs git remote prune
The commands:
# list your remote-tracking branches
git branch -r
# fetch, and drop references the remote no longer has
git fetch --prune
# same cleanup for one remote, without fetching new data
git remote prune origin
# check the result
git branch -r
The part worth being clear about: pruning does NOT delete your local branches, and it does NOT delete branches on the remote. It only removes references to branches that are already gone. Clean references — not actual branches.
If you have several remotes configured, prune the one you mean.
Chapters:
00:00 — The Problem with Old Git Branches
00:10 — Why Remote Branches Become Cluttered
00:25 — What Is Git Prune?
00:40 — How Remote Pruning Works
01:00 — Practical Git Commands
01:25 — Benefits and Important Warnings
01:45 — The Takeaway
A clean repository makes teamwork easier.
#git #github #versioncontrol #gitbranch #developer #programming #softwareengineering #devops #rubyonrails #coding #webdevelopment #gitcommands #codingtips #softwaredevelopment #backend
— #Astmation —
#software #systems, #automation, and #AI-powered #applications.
Build. Automate. Evolve.
https://astmation.com/
Watch on YouTube