Skip to content

gitprune

Brandon Shoop edited this page Jun 2, 2026 · 1 revision

gitprune

Deletes local git branches that no longer exist on the remote, then runs garbage collection and prunes remote-tracking refs.

Usage

gitprune          # safe delete
gitprune --force  # force delete unmerged branches too

Flags

Flag Behavior
(none) Uses git branch -d — refuses to delete unmerged branches
--force Uses git branch -D — deletes unmerged branches

What it does

  1. Lists remote branches (git branch -r)
  2. Compares against local tracking branches (git branch -vv)
  3. Deletes any local branch with no matching remote
  4. Runs git gc --prune=now and git fetch -p to clean up stale refs
  5. Runs git gc again for a final compaction

Output from gc and fetch is piped through show_progress so only a single overwriting status line is shown.

Notes

  • Safe to run frequently — without --force it will never delete a branch with unmerged commits
  • gitrefresh calls gitprune --force automatically at the end of its flow

Clone this wiki locally