Take a look at your repository from a new perspective with Git Machete Plugin!

Mikołaj Kondratek
Nov 19 · 4 min read
Image for post
Image for post

Creating and maintaining small, focused, easy-to-review PRs is a comfortable and desired approach for both the authors and, especially, the reviewers. We created a plugin that eases the management of two and more branches in the repository while also promoting the creation of small PRs — a git repository organizer and a rebase/merge/push/pull automation tool, named Git Machete.

Image for post
Image for post

It allows for looking at the state of the repository from a previously unknown perspective. It puts the primary focus on branches (rather than commits), their relationship with each other and with the remote repository. It finds an outstanding application in maintaining linear Git history.

Git Machete Status Graph

Image for post
Image for post
Git Machete Tab

The picture above presents the demo repository filter-service with a few branches.

It contains two root branchesdevelop and master. The first of them has two child branchesallow-ownership-link (with a child branch of its own — build-chain), and call-ws.

Each line contains a name of a branch, an optional custom annotation, and relation to the remote branch.

Without going into details, the green edge indicates the desired state — the tip of the child branch is a direct descendant of the parent branch tip (i.e. all commits reachable from the parent are also reachable from the child). On the other hand, the red edge tells us the opposite — the tip of the child branch is not a direct descendant of the parent branch tip.

In most cases, an edge becomes red after committing some changes to the parent branch (review fixes) or pulling new commits to the parent from a remote.

Machete File

Image for post
Image for post
Machete file

The branches presented within the graph are defined in a simple configuration file (.git/machete), which can be easily opened from the plugin’s toolbar. It supports both syntax highlighting and completion of local branch names. The graph is automatically refreshed when .git/machete is modified.

Bear in mind that there is no need to edit the machete file manually to set up your branch layout tree. Feel free to use Discover Branch Layout functionality that will find it out for you automatically. It can be performed from Help -> Find Action… (default shortcut: Ctrl + Shift + A). Furthermore, the discovery happens in the case of a missing or empty machete file (although the discovered layout might require some manual changes).

Lights, Camera… Actions

Among the others, there is Rebase onto Parent (that performs interactive rebase of a given branch onto its parent), Push and Pull. Let’s have a look at the following example…

Image for post
Image for post
Git Machete — Actions — Before

Branch allow-ownership-link is out of sync (red edge) to its parent — develop. Furthermore, it is ahead of its remote branch (origin/develop). With Git Machete we can quickly and conveniently lead it to the desired state.

First, Checkout and Rebase Branch Onto Parent. That will perform an interactive rebase from IntelliJ. Once the rebase is finished, the branch is in sync (green edge) with its parent.

VCS Log Rebase

Image for post
Image for post
Rebase From VCS Log

Git Machete Rebase

Image for post
Image for post
Rebase From Git Machete

Now all that’s left is to Push…. This action opens a (force) push dialog. After a successful push, the remote branch is up to date with its remote branch.

The final repository status is shown below.

Image for post
Image for post
Git Machete — Actions — After

Try it now

For additional reference, see the project on GitHub.

VirtusLab

Virtus Lab company blog

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store