Yeah okay, but what is TIG?

You’re right, I didn’t give you any details yet. It’s actually quite simple.

As his creator would say, TIG is an ncurses-based text-mode interface for GIT. It means that TIG offers you an (incredibly fast) UI for GIT, providing a lots a shortcuts to browse repositories, branches, to commit, stage, stash, blame — you name it.

💡 Thank you sir, but what is “ncurses”? ncurses (new curses) is a programming library providing an application programming interface (API) that allows the programmer to write text-based user interfaces in a terminal-independent manner.

Wikipedia explains it way better than me, you get the idea. Maybe you are more familiar with Htop? That’s the same basic concept.

Installation

So here we go, let’s install it.

TIG is available on every OS and distributions (even Windows). You can take a look at the documentation if yours is not among the two below:

Debian & Ubuntu : apt-get install tig

MacOS : brew install tig

Nothing much to do. You’re all set? Let’s use it.

Better, Faster, Stronger with TIG

Do you remember what we did with GIT earlier ? I asked you to keep in mind the laboriousness of the process, now is the time to remember and do the same with TIG in a much faster way !

Main view

Let’s start and launch TIG, just type tig in your terminal. You get the main view also called the history view. Basically it’s the commit history of your current branch, a fancy git log with the date, author, tree and commit message.

You can navigate through the commits using the up and down arrow keys. Pressing Enter on a row opens that commit in a split diff view. You can navigate through this view with the j and k keys. You can also show the commit id by pressing X(shift+x) .

There’s a bunch of other shortcuts for this view but I’ll talk about that later.

I bet you’re looking forward to taking a better look. Here it is:

TIG’s main view: commit browsing, commit diff

Note that I used Key-mon to overlay the key pressed for the example.

Status view

In my humble opinion in the main view, you can now access the best feature: the status view pressing S (shift+s) . We have 3 categories here :

Changes to be committed (files added) Changes not staged for commit (files updated) Untracked files (files not added yet)

Pressing u on any file moves it to the next logical stage. An untracked (3) file moves to Changes to be committed (1) (it performs a git add) and vice-versa (git reset this time). An updated (2) file will move the Changes to be committed (1) and vice-versa. Pressing ! on an updated file will ask you to revert it.

❓ What if I want to add every updated files, not one by one?



No worries! If you press u on a category name, it moves all the files in it!

Last but not least: commit! Just press C(shift+c) on this view, and your favorite editor will open. Write the commit message and save, it’s that simple.

Basically, committing a file could be as simple as tig + S(shift+s) + u + C(shift+c) .

Let’s see some actions now with the ponies scenario we discussed earlier. It shows you how it can be done in a few seconds:

The “laborious” example we had earlier now improved with Tig’s swiftness.

What happened? I’m aware that even with the keys overlay, it’s pretty hard to follow all the steps. Let me describe the workflow:

We entered TIG, pressed S to access the status view.

to access the status view. We checked the diff of the updated file by pressing Enter and added it pressing u

and added it pressing We added the two other files by pressing u on the “Untracked” category.

on the “Untracked” category. We checked the blue pony and were eventually not satisfied with it so we decided to reset it by pressing u and to revert it by pressing ! + y .

and to revert it by pressing . We also reseted the yellow pony by pressing u on it because we wanted to have a commit for each pony.

on it because we wanted to have a commit for each pony. We then commited the red pony by pressing C

Finally, we added the yellow pony by pressing u and commited it with C , quit with q and pushed the branch.

I know, that’s a lot of shortcuts, but I can assure you that with just a little bit of practice, it’s effortless and natural. :)

Pro Tips: Take a look at the bottom of the screen. There’s always a blue highlighted line with useful information in it. In the previous example, Tig’s giving you shortcuts based on your position.

A little further

Do you remember when we wanted to revert a commit using the git log command? Well, let’s revert the yellow pony with TIG! Let me show you:

Let’s describe one more time what we did:

We entered TIG, we were directly on the main view (fancy git log ).

). We browsed the commits of our branch, selected the one we want to revert.

By pressing Enter we could do more by checking the content.

we could do more by checking the content. Then we pressed ! and TIG automatically performed a git revert , we saved and pressed q to leave and then we pushed.

As you can see, we didn’t have to care about the commit id, copy/past or anything, everything was smooth and effortless.

😢 I don’t understand, typing ! didn’t revert the commit. Instead, I have the Unknown key, press h for help message!



That’s totally normal! And that makes a beautiful introduction for the last part of this article.

Going further with customization

I admit it, I lied a little with the last scenario we did together about the revert.

But that’s for the greater good: let me introduce you the configuration. Indeed, TIG allows you to create your own configuration file to custom colors, to set permanent options or to set bindings.

Bindings configuration

We are going to fix this revert issue. First, all you need to do is to create the ~/.tigrc file and type:

Let me explain: we chose to bind the character ! on the main view. The !? means that the external command (!) git revert will ask for confirmation (?) before it’s run. Finally, the %(commit) will be replaced by the commit we highlighted on the main view.

Now you can revert a commit with ! on the main view! Congratz!

That’s pretty powerful since you can now add every command you want under a single bind on each view.

More binds to ease your life!

That’s common knowledge that we webdevs are lazy (and that’s a good thing right ?). One bind is not enough, I’m sure you want more! Let me give you the ones I regularly use:

Those are self- explanatory: Now we have, among others, shortcuts to amend and push force on the status view! Let’s try to amend the yellow pony:

Amend and push force with TIG and custom bindings

Only 5 major inputs: tig S(shift+s) u a P(shift+p) and it’s done in 5s! With GIT, it would have been:

If you want more binds, there is an excellent cheatsheet with many bindings on the TIG’s wiki page.

Of course, what we saw with bindings is just a little part of what’s possible with ~/.tigrc . Don’t hesitate to get a closer look at the doc.

What now?

Now you know how to commit, amend and revert as fast as lightning ⚡️

That’s only the beginning of your journey with TIG. Try this command tig grep "if" in one of your dev project and see what it outputs. Try tig show sha1OfAnyOfYourCommits or maybe tig blame anyOfYourFile . There are also many more views: Tree, blame, stash, log, ref views… I mean, there’s a lot! Just hit h on the main view to get a preview of what’s possible.

Here is the Github page to discover it all or if you simply want to give a star or even contribute. :)