Clean up local Git branches that no longer exist on remote.
Similar to git-sweep, but specifically designed to delete local branches marked as "gone" (i.e., their remote tracking branches have been deleted).
After pull requests are merged and remote branches are deleted, your local repository still contains those branches. Over time, this clutter builds up. Running git branch -vv shows them with a [origin/branch: gone] marker.
git-local-sweep makes it easy to identify and delete these orphaned local branches.
The package exposes a short alias: gls.
npm install -g @cryterion/git-local-sweepThis installs both commands:
git-local-sweepgls
curl -fsSL https://raw.githubusercontent.com/mphassani/git-local-sweep/main/install.sh | bashOr using wget:
wget -qO- https://raw.githubusercontent.com/mphassani/git-local-sweep/main/install.sh | bash- Download the script:
curl -fsSL https://raw.githubusercontent.com/mphassani/git-local-sweep/main/git-local-sweep -o git-local-sweep- Make it executable:
chmod +x git-local-sweep- Move it to a directory in your PATH:
sudo mv git-local-sweep /usr/local/bin/
sudo ln -sf /usr/local/bin/git-local-sweep /usr/local/bin/glsOr for user-only installation:
mkdir -p ~/.local/bin
mv git-local-sweep ~/.local/bin/
ln -sf ~/.local/bin/git-local-sweep ~/.local/bin/gls
# Add ~/.local/bin to your PATH if not already there
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc # or ~/.zshrcIf installed via npm, update with:
npm install -g @cryterion/git-local-sweep@latestIf you run git-local-sweep update (or gls update) from an npm-managed install, the command guides you to the npm update flow.
If installed via install.sh or manual copy, run:
git-local-sweep updateOr re-run the installer:
curl -fsSL https://raw.githubusercontent.com/mphassani/git-local-sweep/main/install.sh | bashgit-local-sweep preview
# or
gls previewThis shows you which local branches are marked as "gone" from remote without deleting anything.
Before listing branches, the tool refreshes remote tracking data with a git fetch --all --prune check.
git-local-sweep cleanup
# or
gls cleanupThis will show you the branches and prompt for confirmation before deleting them.
At the prompt, y or just pressing Enter confirms deletion.
git-local-sweep cleanup --force
# or
gls cleanup --forceDeletes branches without prompting for confirmation. Use with caution!
git-local-sweep --version
# or
gls --versionShows the currently installed version.
git-local-sweep update
# or
gls updateFor npm-managed installs, this recommends the npm global update command. For shell/manual installs, this checks for and applies script updates.
$ git-local-sweep preview
These local branches are gone from remote:
feature/old-feature
bugfix/fixed-bug
experiment/test-idea
To delete them, run again with `git-local-sweep cleanup`
$ git-local-sweep cleanup
These local branches are gone from remote:
feature/old-feature
bugfix/fixed-bug
experiment/test-idea
Delete these branches? ([Y]/n)
deleting feature/old-feature (done)
deleting bugfix/fixed-bug (done)
deleting experiment/test-idea (done)
All done!- Python 3.6 or higher
- Git
- npm (only required for npm install/update/release flows)
Use Bun scripts to keep package.json and the CLI script version in sync:
bun run check:version-sync
bun run version:patch
# or: bun run version:minor
# or: bun run version:majorAfter bumping, commit and merge to main. The release workflow then:
- Confirms version sync
- Checks whether version increased from the previous
maincommit - Creates GitHub Release
vX.Y.Zif missing - Publishes
@cryterion/git-local-sweep@X.Y.Zto npm if not already published
- Configure npm Trusted Publishing (OIDC) for this repository:
- npm package:
@cryterion/git-local-sweep - GitHub repo:
mphassani/git-local-sweep - Workflow file:
.github/workflows/release.yml
- npm package:
- Ensure the
@cryterionnpm scope allows public packages.
Run once from the repository root (after version sync check):
npm publish --access publicThe release workflow is idempotent, so if this version is already on npm it will skip publishing and continue safely.
The script:
- Runs
git branch -vvto get detailed branch information - Identifies branches with the
[origin/...: gone]marker - Uses
git branch -Dto force-delete these branches
Contributions are welcome! Feel free to submit issues or pull requests.
MIT License - see LICENSE file for details.
Created by Parsa Hassani (@mphassani)