Better Programming

Advice for programmers.

Follow publication

Member-only story

This Powerful Command Line Tool Undoes Your Errors With Git

Mirco | VerboseMode.dev
Better Programming
Published in
4 min readOct 3, 2022

--

Photo by Sarah Kilian on Unsplash

Git is nearly the standard solution for version control systems. There are others, Perforce for example, but the vast majority of developers use git. It is one tool that is easy to learn but hard to master.

The basics are easy to grasp. You add changes to the staging area, add them to the commit tree and push them to a remote repository. What do you do if it goes wrong? “Uncommit” is not a thing. There is no universal undo in git.

This is the “hard to master” part. To change a commit message, you have to rebase or use amend. Accidentally deleted a tag? You “just” have to use three commands to get it back. Undoing unwanted changes may cost you a lot of effort.

Ugit is a command-line tool that helps you to undo your mistakes interactively.

Installation

Before we can install ugit, we need to install fzf first, as ugit is using it internally. Fzf is another cool tool, a command-line fuzzy finder, which I will cover in another article. We can install it simply with our default package manager. As always, I tested everything you see here on Ubuntu 22.04 LTS.

sudo apt install fzf

Ugit, on the other side, is not available via package managers. You can clone the repository and run the install script or you just use the following command:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/Bhupesh-V/ugit/master/install)"

However, I strongly suggest not running arbitrary, unchecked scripts directly! Head over to GitHub, clone the repository, look at the script first and then run it.

Ugit in Action

After installation, just type ugit into your terminal and press Enter.

ugit interface

Ugit can undo many different git commands. You can select the appropriate one using the arrow keys. Let us add a commit and undo it right away.

--

--

Mirco | VerboseMode.dev
Mirco | VerboseMode.dev

Written by Mirco | VerboseMode.dev

Backend Developer. My opinions are my own.

Responses (1)

Write a response