Skip to main content

Clean up your local git branches to match the remote with one command.

Project description

git-prune

Clean up your local git branches to match the remote with one command. This tool synchronizes local git branches with remote branches by removing orphaned local branches that don't exist upstream.

PyPI - version Python License: MIT

Installation

pip install git-prune

Usage

Basic Usage

Run from the repository you want to prune:

git-prune

This will:

  1. Fetch latest remote references (git fetch -p)
  2. List local-only branches that don't exist on remote
  3. Ask for confirmation before deletion
  4. Delete confirmed branches

Specify Target Directory

Prune a different repository:

git-prune -d /Path/to/repository
git-prune --directory /Path/to/repository

What Git Prune Does

  1. Fetches remote references to ensure up-to-date branch list
  2. Compares local branches against remote branches
  3. Reports which branches exist locally but not on remote
  4. Deletes orphaned branches after confirmation

Example Output

Branches ['feature-old-thing', 'temp-experiment'] do not exist in the origin repository. Would you like to delete them? y/N:

Safety Features

  • Fetches first: Always runs git fetch -p before any deletions to ensure you have the latest remote state
  • Requires confirmation: Never deletes without explicit 'y' approval
  • Protects current branch: Switches to a safe target branch (main/master or first remote branch) before deleting branches you're currently on

How It Works

Git Prune uses git fetch -p to prune stale remote tracking references, then compares local branch refs against remote branch refs to identify branches that should be removed.

Before:

  • Local: main, feature-old-thing, temp-experiment
  • Remote: main, feature-new-stuff

After running git-prune (with confirmation):

  • Local: main
  • Remote: main, feature-new-stuff

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_prune-1.0.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_prune-1.0.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file git_prune-1.0.2.tar.gz.

File metadata

  • Download URL: git_prune-1.0.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for git_prune-1.0.2.tar.gz
Algorithm Hash digest
SHA256 479c712d2b18fe15ac067e4d38cd27230b25bc924d328432ea70df42c8942427
MD5 9b6482785826b0c4096f0c947f3eea96
BLAKE2b-256 70fffe73c74ac14754cb4184262094cefa18027b8502352321575a395be9060d

See more details on using hashes here.

File details

Details for the file git_prune-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: git_prune-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for git_prune-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7d2ca8bb627eec9d17e72d4429d0567324e82e8a2b001fcb9e8296b0f8e74614
MD5 b810ad0ca7a36a82d39add2d76ceb65a
BLAKE2b-256 88e10fb293cf35af0855101d32be286a0c0ae1b37f6ef39df755c45e2db2add1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page