Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidraviv/gh-clean-branches
Safely deletes local branches with no upstream and no un-pushed commits
https://github.com/davidraviv/gh-clean-branches
cli gh-extension git-branches local-environment
Last synced: about 2 months ago
JSON representation
Safely deletes local branches with no upstream and no un-pushed commits
- Host: GitHub
- URL: https://github.com/davidraviv/gh-clean-branches
- Owner: davidraviv
- License: mit
- Created: 2021-08-25T07:15:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-26T16:02:05.000Z (about 2 years ago)
- Last Synced: 2024-11-13T09:40:54.472Z (2 months ago)
- Topics: cli, gh-extension, git-branches, local-environment
- Language: Shell
- Homepage:
- Size: 27.3 KB
- Stars: 177
- Watchers: 5
- Forks: 15
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-gh-cli-extensions - **clean-branches** - Safely delete local branches that have no remotes and no hanging changes. (Git)
- jimsghstars - davidraviv/gh-clean-branches - Safely deletes local branches with no upstream and no un-pushed commits (Shell)
README
# Clean Branches
## Description
Github CLI extensionSafely delete local branches that have no remotes and no hanging changes.
The extension uses `git branch -d` to delete the local branches, hence it will not delete branches with un-pushed changes
unless using `--force` flag.The extension supports single or multiple upstream.
## Installation
```bash
gh extension install davidraviv/gh-clean-branches
```## Usage
Execute it inside a git repo folder:
```bash
gh clean-branches [--dry-run] [--force] [--verbose]
```
### Options- `--dry-run` See the list of branches to be deleted before actually deleting them.
- `--force` Uses `git branch -D` forcing a branch to be deleted regardless if upstream branches have local changes. Use carefully!
- `--verbose` Print all log statements.## Script flow
- Fetches the repo
- Checkout the default branch (e.g `main`) and pull changes (needed if we want to delete the current branch)
- Lists all remote branches _(only with `--verbose` flag)_
- Lists all local branches _(only with `--verbose` flag)_
- Lists branches with missing upstream to be deleted
- Deletes branches with no upstream and no un-pushed changes _(Skipped on `--dry-run`)_
- Checkout the branch we started with unless it was deleted, then stays on the default branch## Dependencies
The extension depends on:
- zsh
- git v2.22
- gh CLI v2.0