git-trim automatically trims your git remote tracking branches that are merged or gone.
Download binary from Releases, and put it under your
You can also install with
cargo install git-trim if you have
git2 under the hood which depends conditionally on
openssl-sys on *nix platform.
You might need to install
pkg-config packages if you build from the source. See: https://docs.rs/openssl/0.10.28/openssl/#automatic
How to use
- Don't forget to set an upstream for a branch that you want to trim automatically.
git push -u <remote> <branch>will set an upstream for you on push.
git trimif you need to trim branches especially after PR reviews. It'll automatically recognize merged or gone branches, and delete it.
- If you need more power, try
git trim --filter all
- You can also
git trim --dry-runwhen you don't trust me.
Why have you made this? Show me how it works.
Git's PR workflow is a little bit tedious as a routine.
There are so many lines of commands to type and many statuses of branches that corresponding to PRs that you've sent. Were they merged or rejected? Did I forget to delete the remote branch after it is merged?
After some working with the repository, you'll execute
git fetch --prune or
git remote update --prune occasionally. However, you'll likely see the mess of local branches that are already merged and removed on the remote. Because
git fetch --prune only deletes
refs/remotes/<remote>/<branch> but not corresponding
refs/heads/<branch> for you. It is worse if remote branches that are merged but the maintainer forgot to delete them, the
refs/remotes/<remote>/<branch> would not be removed and so on even if you know that it is merged into the master.
They are tedious to remove manually.
git branch --merged'll likely to betray you it is rebase merged or squash merged
After the PR is merged or rejected, you're likely to delete them manually if you don't have
git-trim but it is tedious to type and error-prone.
You repeat these same commands as much as PRs that you've sent.
You have to remember what branch is for the PR that just have been closed and it is easy to make a mistake.
I feel nervous whenever I put
--force flag. Rebase merge forces to me to use
--force (no pun is intended).
git reflog is a fun command to play with, isn't it? Also
git remote update and
git push is not instantaneous.
I hate to wait for the prompt even it is a fraction of a second when I have multiple commands to type.
It is enough to type just
git trim and hit the
y key once.
That's why I've made
It knows whether a branch is merged into the default base branch, or whether it is rejected.
It can even
push --delete when you forgot to delete the remote branch if needed.
What kind of merge styles that
- A classic merge with a merge commit with
git merge --no-ff
- A rebase merge with
git merge --ff-only
- A squash merge with
git merge --squash(With this method: https://stackoverflow.com/a/56026209)
What is the difference between the
A merged branch is a branch that you can safely remove them. It is already merged into the base branch, so you're not going to lose the changes.
However, your PRs are sometimes rejected and deleted from the remote.
Or you might forget the fact that the PR is merged.
So you might have been mistakenly amended or rebased the branch and the patch is now completely different from the patch that is merged.
Then it is
gone, which means that you might lose your changes. The term is borrowed from the git's remote tracking states.
Git and the Git logo are either registered trademarks or trademarks of Software Freedom Conservancy, Inc., corporate home of the Git Project, in the United States and/or other countries.
Images of a man with heartburn are generated with https://gvsc.rajephon.dev