Member-only story
This Powerful Command Line Tool Undoes Your Errors With Git
ugit is the universal “git undo” tool

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 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.