Delete all those annoying untracked local Git branches in one fell swoop.
delete-untracked-git-branches is a command-line tool that helps you clean up your local Git repository by deleting branches that are no longer tracked by a remote repository or have been merged. This is particularly useful when you have numerous local branches that are not needed anymore, and you want to delete them quickly without manually checking each one.
Note: Ensure that you don't have any uncommitted changes before running the script, as it might encounter issues or cause data loss.
You can install delete-untracked-git-branches globally using npm:
npm install -g delete-untracked-git-branchesAlternatively, install it as a development dependency in your project:
npm install --save-dev delete-untracked-git-branchesOr, you can use it without installing by using npx:
npx delete-untracked-git-branches [options]The delete-untracked-git-branches script supports the following options:
| Option | Alias | Description | Type | Default |
|---|---|---|---|---|
--checkout-branch |
-c |
The branch to checkout before performing the branch deletions. | string |
|
--protected-branches |
-p |
List of branches to exclude from deletion. | array |
|
--dry-run |
-d |
Lists untracked branches without deleting them. | boolean |
false |
To delete all your untracked branches:
delete-untracked-git-branchesIf you want to checkout another branch (e.g., development) before deleting untracked branches:
delete-untracked-git-branches -c developmentTo protect certain branches (e.g., development and main) from being deleted, pass them as an array by either separating them with spaces, or declaring the flag multiple times:
# Option 1: Space-separated
delete-untracked-git-branches -p development main
# Option 2: Multiple flags
delete-untracked-git-branches -p development -p main(Note: Comma-separated strings like -p development,main are also supported for backwards compatibility)
To list all untracked branches without deleting them (dry run):
delete-untracked-git-branches -dThis command will display the branches that would be deleted without actually deleting them.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License - see the LICENSE file for details.