Git-gone
Git daily usage
If you’re like most developers nowadays you make an extensive usage
of git
across a large number of repositories.
The now-classic branching model that consists in using a branch for every fix / feature / experiment before creating a merge request is perfect for collaborating efficiently. However it comes with one downside, local branches can quickly become messy and removing stale branches is not that easy
Removing remote branches
git
is a really well designed tool and removing remote
references from your local repository is easily done by
This will remove local references to non existing branches, however
it is not useful to remember this command, we can configure
git
so that it prunes automatically on fetching :
Removing local branches
This is where things can be quite messy, as local branches might have been merged, rebased, or squashed, and “classic” commands allowing to detected merged branches are not always working as they ought.
If you search how to clean up local branches, you might find a lot
of commands involving git branch --merged
with
grep
and xargs
all the way.
I found out a little neat tool to do so, called
git-gone
(github/lunaryorn/git-gone), written in Rust 🧡
Install it
As all rust project, it is packaged and easy to install using cargo
List branches to prune
Before doing anything silly, we can list the branches that are
candidate to removal (the -f
flag forces fetching
remote)
Prune’em all
And finally, you can remove them (the -f
flag is still
here to sync with remote)
git-gone
is even clever enough to give you the command
to restore a branch if change your mind (as long as you did not
git gc
the revision is still available locally, so you
can restore it)