Added Readme
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
# cleanupGoneBranches
|
||||
|
||||
A small command-line utility written in Go that helps you clean up **local Git branches whose remote counterparts have already been deleted** ("gone" branches).
|
||||
|
||||
Instead of manually finding and deleting stale branches, this tool:
|
||||
|
||||
- Fetches and prunes your remote references
|
||||
- Detects local branches whose upstream no longer exists
|
||||
- Lets you interactively select which branches to delete
|
||||
- Protects your current branch from accidental deletion
|
||||
- Supports automatic cleanup and forced deletion
|
||||
|
||||
## Features
|
||||
|
||||
- ✅ Runs `git fetch --prune`
|
||||
- ✅ Detects local branches with deleted remotes
|
||||
- ✅ Interactive branch selection
|
||||
- ✅ Range selection (`1,3-5`)
|
||||
- ✅ Select all (`all`)
|
||||
- ✅ Confirmation before deleting
|
||||
- ✅ Never deletes the currently checked-out branch
|
||||
- ✅ Optional forced deletion (`git branch -D`)
|
||||
- ✅ Show-only mode
|
||||
- ✅ Display equivalent manual Git commands
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
### Build from source
|
||||
|
||||
```bash
|
||||
git clone <repository>
|
||||
cd cleanupGoneBranches
|
||||
|
||||
go build -o cleanupGoneBranches
|
||||
```
|
||||
|
||||
Or install directly:
|
||||
|
||||
```bash
|
||||
go install
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
cleanupGoneBranches [options]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Description |
|
||||
|---------|-------------|
|
||||
| `--show` | Show gone branches only (don't delete anything) |
|
||||
| `--all` | Select all gone branches automatically (still asks for confirmation) |
|
||||
| `--force` | Use `git branch -D` instead of `git branch -d` |
|
||||
| `--info` | Show the equivalent manual Git commands |
|
||||
| `-h`, `--help` | Show help |
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
|
||||
```
|
||||
$ cleanupGoneBranches
|
||||
|
||||
Git fetch mit prune...
|
||||
|
||||
Gefundene lokale Branches mit gelöschtem Remote (gone):
|
||||
|
||||
1) feature/login
|
||||
2) bugfix/navbar
|
||||
3) old-experiment
|
||||
|
||||
Auswahl eingeben, z.B. 1,3-5 oder all. Leer lassen zum Abbrechen.
|
||||
|
||||
Auswahl: 1,3
|
||||
|
||||
Es werden diese Branches gelöscht:
|
||||
|
||||
- feature/login
|
||||
- old-experiment
|
||||
|
||||
Wirklich löschen? (y/N): y
|
||||
|
||||
Lösche Branches...
|
||||
|
||||
Deleted branch feature/login
|
||||
Deleted branch old-experiment
|
||||
|
||||
Fertig.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Selection Syntax
|
||||
|
||||
You can select branches using:
|
||||
|
||||
| Input | Meaning |
|
||||
|--------|---------|
|
||||
| `1` | Delete branch #1 |
|
||||
| `1,4,7` | Delete branches 1, 4, and 7 |
|
||||
| `2-5` | Delete branches 2 through 5 |
|
||||
| `1,3-6` | Mixed selection |
|
||||
| `all` | Select every gone branch |
|
||||
|
||||
Leaving the prompt empty cancels the operation.
|
||||
|
||||
---
|
||||
|
||||
## Safe by Default
|
||||
|
||||
By default the tool uses:
|
||||
|
||||
```bash
|
||||
git branch -d
|
||||
```
|
||||
|
||||
which only deletes branches that Git considers safely merged.
|
||||
|
||||
If you want to force deletion, use:
|
||||
|
||||
```bash
|
||||
cleanupGoneBranches --force
|
||||
```
|
||||
|
||||
which uses:
|
||||
|
||||
```bash
|
||||
git branch -D
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Show Gone Branches Only
|
||||
|
||||
```bash
|
||||
cleanupGoneBranches --show
|
||||
```
|
||||
|
||||
Useful if you just want to inspect stale branches.
|
||||
|
||||
---
|
||||
|
||||
## Delete Everything
|
||||
|
||||
```bash
|
||||
cleanupGoneBranches --all
|
||||
```
|
||||
|
||||
All gone branches are selected automatically, but you'll still be asked for confirmation before deletion.
|
||||
|
||||
---
|
||||
|
||||
## Manual Git Equivalent
|
||||
|
||||
Run:
|
||||
|
||||
```bash
|
||||
cleanupGoneBranches --info
|
||||
```
|
||||
|
||||
to display the Git commands that perform the same operations manually.
|
||||
|
||||
---
|
||||
|
||||
## Requirements
|
||||
|
||||
- Go 1.20+ (for building)
|
||||
- Git installed and available in your `PATH`
|
||||
- Must be executed inside a Git repository
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
- The currently checked-out branch is never deleted.
|
||||
- The tool automatically runs `git fetch --prune` before searching for gone branches.
|
||||
- Branches are always sorted alphabetically.
|
||||
- A confirmation prompt is shown before any deletion occurs.
|
||||
|
||||
Reference in New Issue
Block a user