Manage Git Branches with git-trim
Have you ever needed to clean up stale or old local branches that have already been merged and deleted on GitHub? Jason McCreary has released a CLI tool for organizing local and remote branches:
Cleaning up thousands of dangling references in Git repos everywhere - another "Garbage Man" production. 🗑😎https://t.co/fW4yTkPSJt
— Jason McCreary 🗑 (@gonedark) February 9, 2022
The git-trim
command is a way to quickly remove merged, pruned, untracked, and stale branches in Git repositories:
1# Removes local branches where its remote branch no longer exists 2git trim 3git trim --pruned 4 5# Removes local branches already merged into the current branch 6git trim --merged 7 8# Removes local branches without commits in the last 3 months 9git trim --stale10 11# Removes local branches not tracking a remote branch12git trim --untracked13 14# Removes all local branches except the current branch (requires confirmation)15git trim --all
You can also combine these when it makes sense, such as removing merged and stale branches:
1git-trim --merged --stale
You can download and try this command out via NPM or as an Oh-My-Zsh plugin. If you'd like to learn more about the source code, you can check it out on GitHub at jasonmccreary/git-trim.
by laravel-news . com