https://github.com/svandriel/remove-merged-branches
Removes merged git branches
https://github.com/svandriel/remove-merged-branches
branch git merged remove
Last synced: 6 months ago
JSON representation
Removes merged git branches
- Host: GitHub
- URL: https://github.com/svandriel/remove-merged-branches
- Owner: svandriel
- License: mit
- Created: 2022-11-15T18:21:20.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-09-25T19:33:49.000Z (almost 2 years ago)
- Last Synced: 2024-12-11T14:54:54.904Z (over 1 year ago)
- Topics: branch, git, merged, remove
- Language: TypeScript
- Homepage:
- Size: 1000 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# remove-merged-branches
[](https://github.com/svandriel/remove-merged-branches/actions/workflows/node.js.yml)

Command line tool removing all branches that have been merged to the current branch.
Supports dry runs and offline use.
It can be used to remove both _local_ and _remote_ branches.
## Usage
Install globally:
```
npm i -g remove-merged-branches
```
And then you just call:
```
rmb
```
...or if you prefer verbosity, enter `remove-merged-branches`
## Syntax
```
Usage: rmb [options]
Removes merged branches locally and remotely
Options:
-V, --version output the version number
-b, --branch Base branch to compare others to (default: "HEAD")
-o, --offline Runs without doing anything to remotes (default: false)
--verbose Shows more output (default: false)
--dry-run Performs a dry run instead of removing branches (default: false)
-h, --help output usage information
```
## What does it do?
First it clears out the local branches that have been removed on the remotes:
```bash
git fetch --prune
```
Then, it finds all **local** branches merged to the HEAD branch and removes them:
```bash
git branch --merged $(git rev-parse HEAD)
# Then calls 'git branch -d' on each merged branch
```
Then, it finds all **remote** branches merged to the HEAD branch and removes them:
```bash
git branch --remote --merged $(git rev-parse HEAD)
# Then call 'git push --no-verify --delete' on each origin and branch
```
Finally, it clears out the local branches that have been removed due to the previous action:
```bash
git fetch --prune
```
## Example output
```
INFO Pruning branches removed on remotes
INFO Removing local branch feature/add-badges-to-markdown, feature/add-more-time-logs, feature/change-ci, feature/refactor-ssh-exec-cmd, refactor/extract-remove-undefineds
INFO No remote merged branches to HEAD found
INFO Pruning branches removed on remotes
```