GIT enhanced with TIG

Vincent Tommasi
8 min readSep 19, 2018

Every webdevs on Earth has most likely already used, or at least heard of GIT once in their lives. People usually tend to say that GIT is complicated and pretty hard to use at first, but better and more flexible than any other version control software at the end of the day.

Well in a way I would say they’re right. There are lots a commands to learn, remember and use just to achieve a simple task. But that’s what’s making it awesome and powerful.

The thing they don’t tell you though is that some tools like TIG exists and can really ease the use of GIT, to make it even more powerful. That’s what I want to talk about today. :)

How we work with GIT

First of all, I would like to review some of the usual GIT processes we all use during development. The goal is to show that we’re able to do the exact same thing 10 times faster with TIG.

As you probably know, being a beginner with GIT is quite anxious. A lot of different scenarios, lots of commands to learn and use (sometimes dangerous ones — push -f for instance 😨), it can be overwhelming. Meanwhile, experienced users have other problems: all those commands are long, repetitive and painful to type over and over again. Usually it can be improved with aliases, although it’s not perfect since you have to remember them all.

Let’s use a real life example, assuming you have a wonderful little project about ponies 🐴. You edit your previously created blue pony, you create two more (red & yellow). You now want to commit and push your code. After carefully looking at the diff of your blue pony, you decide to add the edited files. 30 seconds later, obviously you realize your new blue pony won’t be better than the old one so you revert your changes. Then you remember what your lead developer told you: “Different commits for different ponies. Always!”. No problem, you reset the second one, you commit and push the code and finally do the same for the last one to finish this up.

Still there? Ok! Our tiny scenario should most likely look like this:

Okay… I’ll give you that, the first two are not GIT-related, we screwed up with the first git add. Apart from that, 10 commands were needed to do what we wanted. And for how long? Keep that in mind for later. :)

Another interesting GIT command is git log. It’s pretty useful to see the entire commit history of your current branch, get the commit id, author, date… However the interface is not very interactive and not very clear also. Plus, the number of commits you have in your branch since the master branch is not easy to get.

Let’s see how it can be useful with the following scenario: you want to revert the last commit of your current branch. The command you need is git log:

git log output for the branch “ponies”

To revert a commit, you need to copy/paste the commit id you want gone, leave the log screen and then type:

Far from ideal (especially the copy/paste part), since you need to type at least 3 commands.

Ok, that being said, you’re now ready for a better, faster, stronger git experience with TIG!

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 fancygit log with the date, author, tree and commit message.

You can navigate through the commits using the up and downarrow 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 :

  1. Changes to be committed (files added)
  2. Changes not staged for commit (files updated)
  3. Untracked files (files not added yet)

Pressing uon 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 uon 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 Sto access the status view.
  • We checked the diff of the updated file by pressing Enterand added it pressing u
  • We added the two other files by pressing uon the “Untracked” category.
  • We checked the blue pony and were eventually not satisfied with it so we decided to reset it by pressing uand to revert it by pressing ! + y.
  • We also reseted the yellow pony by pressing uon 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 uand commited it with C, quit with qand 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.
  • Then we pressed ! and TIG automatically performed agit 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. :)

Well, you now have all the weapons you need to start TIG. My last words for you reader: try TIG!

--

--