This release is a pre-release and may not be stable for production use.
git-sweep-merged-and-stale
This is based on the excellent git-sweep .
I just added delete_stale_after_days which allows you to specify delete_stale_after_days stale branches we need to delete.
ie: git-sweep-merged-and-stale cleanup --delete_stale_after_days 15 will delete all Branches older than 15 days and those merged in Master.
WARNING: When you delete branches with no active PR, you will lose access to the ability to restore the branch. Please back it up using Github Artifacts or a copy of the branch prior to running this.
- This deletes branches that fulfil either of these:
Merged into Master or the branch you specify by which_master_main OR
Branches older than X days (specified by delete_stale_after_days)
This by default does not work until you set parameter action = cleanup
To install it run:
pip install git-sweep-merged-and-stale || easy_install git-sweep-merged-and-stale
Then to run it in preview mode:
git-sweep-merged-and-stale preview --delete_stale_after_days 30
Then to run it in cleanup mode:
git-sweep-merged-and-stale cleanup --delete_stale_after_days 30
Introduction
A command-line tool that helps you clean up Git branches that have been merged into master.
One of the best features of Git is cheap branches. There are existing branching models like GitHub Flow and Vincent Driessen’s git-flow that describe methods for using this feature.
The problem
Your master branch is typically where all your code lands. All features branches are meant to be short-lived and merged into master once they are completed.
As time marches on, you can build up a long list of branches that are no longer needed. They’ve been merged into master, what do we do with them now?
The answer
Using git-sweep-merged-and-stale you can safely remove remote branches that have been merged into master.
To install it run:
pip install git-sweep-merged-and-stale || easy_install git-sweep-merged-and-stale
Try it for yourself (safely)
To see a list of branches that git-sweep-merged-and-stale detects are merged into your master branch:
You need to have your Git repository as your current working directory.
$ cd myrepo
The preview command doesn’t make any changes to your repo.
$ git-sweep-merged-and-stale preview Fetching from the remote These branches have been merged into master: branch1 branch2 branch3 branch4 branch5 To delete them, run again with `git-sweep-merged-and-stale cleanup`
If you are happy with the list, you can run the command that deletes these branches from the remote, cleanup:
$ git-sweep-merged-and-stale cleanup Fetching from the remote These branches have been merged into master: branch1 branch2 branch3 branch4 branch5 Delete these branches? (y/n) y deleting branch1 (done) deleting branch2 (done) deleting branch3 (done) deleting branch4 (done) deleting branch5 (done) All done! Tell everyone to run `git fetch --prune` to sync with this remote. (you don't have to, yours is synced)
Note: this can take a little time, it’s talking over the tubes to the remote.
You can also give it a different name for your remote and master branches.
$ git-sweep-merged-and-stale preview --master=develop --origin=github ...
Tell it to skip the git fetch that it does by default.
$ git-sweep-merged-and-stale preview --nofetch These branches have been merged into master: branch1 To delete them, run again with `git-sweep-merged-and-stale cleanup --nofetch`
Make it skip certain branches.
$ git-sweep-merged-and-stale preview --skip=develop Fetching from the remote These branches have been merged into master: important-upgrade upgrade-libs derp-removal To delete them, run again with `git-sweep-merged-and-stale cleanup --skip=develop`
Once git-sweep-merged-and-stale finds the branches, you’ll be asked to confirm that you wish to delete them.
Delete these branches? (y/n)
You can use the --force option to bypass this and start deleting immediately.
$ git-sweep-merged-and-stale cleanup --skip=develop --force Fetching from the remote These branches have been merged into master: important-upgrade upgrade-libs derp-removal deleting important-upgrade (done) deleting upgrade-libs (done) deleting derp-removal (done) All done! Tell everyone to run `git fetch --prune` to sync with this remote. (you don't have to, yours is synced)
Deleting local branches
You can also clean up local branches by using simple hack:
$ cd myrepo $ git remote add local $(pwd) $ git-sweep-merged-and-stale cleanup --origin=local
Development
I just use pytest to test this.
Requirements
Git
Python >= 3.6
License
Friendly neighborhood MIT license.
Metadata
Release files for git-sweep-merged-and-stale 1.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| git-sweep-merged-and-stale-1.0b1.tar.gz | 7.7 kB | Without provenance | Details for git-sweep-merged-and-stale-1.0b1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| git_sweep_merged_and_stale-1.0b1-py3-none-any.whl | Python 3 | none | any | Details for git_sweep_merged_and_stale-1.0b1-py3-none-any.whl |
Total release size: 17.3 kB
Release files / git-sweep-merged-and-stale-1.0b1.tar.gz
| Download URL | git-sweep-merged-and-stale-1.0b1.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7976d23c3a56d96833912a99d9f66624abc33e2b2a3edca06810793fe557777d
|
|
BLAKE2b-256 checksum How to use checksums |
4246dfc717cf69f486dab92b9b25fb5538bb6d4cb9c7b4778f5133122812d5dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
|
Release files / git_sweep_merged_and_stale-1.0b1-py3-none-any.whl
| Download URL | git_sweep_merged_and_stale-1.0b1-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c3d2a67f505248712bf4175c4186d59e6db04540b23f8bf8db3983d4449cb52
|
|
BLAKE2b-256 checksum How to use checksums |
dd72c7504f48a6e38c95637f719b18453f9b0d8fc32008bb60f0d21ee691858d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
|
Security for git-sweep-merged-and-stale 1.0b1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.