Skip to main content

Command-line tool to delete merged Git branches

Project description

git-delete-merged-branches

A convenient command-line tool helping you keep repositories clean.

Installation

# pip install git-delete-merged-branches

Example

# git-delete-merged-branches
Do you want to run "git remote update --prune" for 1 remote(s):
  - origin

Update? [y/N] y

Do you want to run "git pull --ff-only" for 1 branches(s):
  - master

Pull? [y/N] y

You are about to delete 6 local branch(es):
  - improve-setup-py
  - issue-12-enable-ci-for-pull-requests
  - issue-5-fix-waste-of-one-second-per-service
  - keep-github-actions-up-to-date
  - refactoring-one
  - simple-ci

Delete? [y/N] y

6 local branch(es) deleted.
You are about to delete 6 remote branch(es):
  - origin/improve-setup-py
  - origin/issue-12-enable-ci-for-pull-requests
  - origin/issue-5-fix-waste-of-one-second-per-service
  - origin/keep-github-actions-up-to-date
  - origin/refactoring-one
  - origin/simple-ci

Delete? [y/N] y
To github.com:hartwork/wait-for-it.git
 - [deleted]         improve-setup-py
 - [deleted]         issue-12-enable-ci-for-pull-requests
 - [deleted]         issue-5-fix-waste-of-one-second-per-service
 - [deleted]         keep-github-actions-up-to-date
 - [deleted]         refactoring-one
 - [deleted]         simple-ci

6 remote branch(es) deleted.

Features

  • Supports deletion of both local and remote branches
  • Detects multiple forms of de-facto merges (rebase merges, squash merges (needs --effort=3), single or range cherry-picks… leveraging git cherry)
  • Supports workflows with multiple release branches, e.g. only delete branches that have been merged to all of master, dev and staging
  • Quick interactive configuration
  • Provider agnostic: Works with GitHub, GitLab, Gitea and any other Git hosting
  • Takes safety seriously

Safety

Deletion is a sharp knife that requires care. While git reflog would have your back in most cases, git-delete-merged-branches takes safety seriously.

Here's what git-delete-merged-branches does for your safety:

  • No branches are deleted without confirmation or passing --yes.
  • Confirmation defaults to "no"; plain [Enter]/[Return] does not delete.
  • git push is used with --force-with-lease so if the server and you have a different understanding of that branch, it is not deleted.
  • There is no use of os.system or shell code to go wrong.
  • With --dry-run you can get a feel for the changes that git-delete-merged-branches would be making to your branches.
  • Show any Git commands run using --verbose.

Best Practices

When the repository is a fork (with an upstream remote and a fork remote):

  • Make sure that release branches are tracking the right remote, e.g. master should probably track original upstream's master rather than master of your fork.
  • Consider keeping your fork's remote master up to date (using git push).

When using GitHub:

Name clash on "git-delete-merged-branches" with git-extras

Utility collection git-extras provides a simple shell script named git-delete-merged-branches that competes for command git-delete-merged-branches when both software packages are installed.

To address this conflict you can:

  • a) Invoke python3 -m git_delete_merged_branches instead of git-delete-merged-branches
  • b) Invoke command git-dmb instead of git-delete-merged-branches
  • c) Control path resolution order through environment variable $PATH
  • d) Invoke git-delete-merged-branches with its absolute path. You can run which -a git-delete-merged-branches to see where it's located.

Support

Please report any bugs that you find.

Like this tool? Support it with a star!

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-delete-merged-branches-6.0.1.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

git_delete_merged_branches-6.0.1-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file git-delete-merged-branches-6.0.1.tar.gz.

File metadata

  • Download URL: git-delete-merged-branches-6.0.1.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.8

File hashes

Hashes for git-delete-merged-branches-6.0.1.tar.gz
Algorithm Hash digest
SHA256 13bb559b0c8ce46e3367d17dd57853dd43f295d41e76022dcf013bdd54ea6347
MD5 94035de0fc43c75297766ad69b4151d0
BLAKE2b-256 e80df88db8ffa33677948e2d73bda518e02d002f2b2ed5ea4a5ee4bd3e9e3499

See more details on using hashes here.

Provenance

File details

Details for the file git_delete_merged_branches-6.0.1-py3-none-any.whl.

File metadata

  • Download URL: git_delete_merged_branches-6.0.1-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.8

File hashes

Hashes for git_delete_merged_branches-6.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 340815d537595c7cc2e55d347cad3e8295cff1a9bcc5ac3aac651dfc238cca38
MD5 fa2c8f1574a178c42ca7f98212bf4ac9
BLAKE2b-256 a671516b8e003d7bb57541362d5561b48ad846904f93f37ceec1bf8c196faf51

See more details on using hashes here.

Provenance

Supported by

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