Clean Remote Branches With Prune | Generated by AI

Home 2025.09

git fetch --prune is a way to keep your local references to remote branches clean and up-to-date.

What it does

So, after running git fetch --prune, your local list of remote branches matches exactly what the remote currently has.

Example

  1. Remote has branches: main, feature-a.
  2. You run git fetch → you now have origin/main, origin/feature-a.
  3. Someone deletes feature-a on the remote.
  4. If you run git fetch, you’ll still see origin/feature-a locally (stale reference).
  5. If you run git fetch --prune, Git will notice feature-a is gone and remove origin/feature-a from your local repo.

Why it’s useful

That way, every git fetch automatically prunes stale branches.


Do you want me to also explain how pruning interacts with tags (since git fetch --prune only handles branches by default, but tags behave differently)?


Back Donate