In this article, we are going show you installation and usage of an awesome tool which is 'tig'. It's a great Git Command Line Tool with ncurses-based text-mode interface for git. Something between the command line and full blown windowed GUI applications would be great to work on like 'tig'. It functions mainly as a Git repository browser, but can also assist in staging changes for commit at chunk level and act as a pager for output from various Git commands. It works insanely fast, just three letters to type, and it instantly shows up. No fussing around with alt-tabbing to another window, pointing your mouse repeatedly or waiting for a JVM to start. It literally loads up to 50,000 commits of the JIRA codebase in a fraction of a second. It’s available in MacPorts and Ubuntu which provides a simple command-line yet visual interface to Git.
How to install Tig on Ubuntu 16
The installation of 'tig' is simple as its already available in the default repository of Ubuntu. Let's open the command line terminal of your Ubuntu 16.04 LTS and run the following command using root.
# apt-get install git
This will install the additional packages required along with their dependencies like 'git', 'git-man' and 'liberror-perl'.
Once you asked, press 'Y' and hit Enter key to continue installation.
Then extract the package and compile it using below commands to install it on your system.
# make install
By default, tig is installed in '$HOME/bin' directory and if you like to install it elsewhere, then set prefix to the desired path using below commands.
# make prefix=/usr/local
# sudo make install prefix=/usr/local
The documentation files such as man pages are distributed in the release tarball which can be installed using below command.
# make install-doc
That's it, the installation will be completed in one go without any problem. Let's move to the next session to start using this awesome visual utility for git.
How to use tig on Ubuntu 16
Using tig is as simple as just running 'tig' after moving into git repository. This will bring up visual git-log where you can navigate up and down the log using the up and down keys similar keys that you used while editing in 'vim' editor. Hit 'Enter' key on a log entry, and it will open a split-pane window with the 'diff' of that 'commit'. The 'Space' key will move you through the diff, while up and down will move you between commits. You can close the split-pane using 'q', if you want to close tig altogether then hit 'q' once again.
1) Main View
This mode shows the entire history of your project in an easy-to-navigate waterfall, with branches and merges mapped visually. If you have used Github to navigate the history of a repo, this will feel familiar. In this mode, you can hit the '/' key to start searching for any text within the view, which is really handy when you’re looking for a particular commit message. From the Main View, you can hit 't' to get into Tree View for the highlighted commit, or 'd' to open Diff View.
2) Tree View
Another use of tig is its tree-view, when you launch tig, hit 't' if you’re in log view, it will bring up a navigable tree view of the repository. By hitting 'Enter' to descend into directories or view files. Tree View lets you explore files and directories in your codebase. If you open a file for viewing, you can hit q to close the file and return to the tree. Views in Tig work like stacks, and hitting q will return you to the View that you were in previously. If you entered Tree View from the Main View, hitting q will return you to it. You can always hit 'm' to return to the main view.
3) Diff View
Diffs show you exactly what a commit did to the codebase, therefore, the Diff View is extremely useful. Hit 'd' from the main menu to view the diff for the highlighted commit. Alternatively, you can hit enter to open Diff View in a split.
4) Status View
The Status View is a huge improvement of tig over git status. Use shift+S to open it in your terminal. This View shows you all of the files that are staged to be committed, as well as unstaged and untracked files. You can just select a file with the arrow keys and hit u to stage it to be committed rather than typing git add file.txt. Hitting u on a staged file will unstaged it. If you want to make a quick edit from Tig, highlight a file and press e to open it in your default Git editor.
One more feature of the Status View is by pressing '!' on a file to revert any changes since the last commit. When you’re ready to commit your changes, hit shift-C to open up your text editor and write a commit message.
5) Refs View
It’s actually a GUI for all of the refs in your Git repo, which includes tags. Refs View is the visual branch selector GUI you’ve always wanted for Git, accessed by hitting 'r'. Its primarily useful for checking out branches by navigating to the branch you want to check out and hit shift-C to switch to it.
Similar, you can run the following command to know about all possible commands to use tig.
# tig --help
tig 2.0.2 (Feb 7 2016)
Usage: tig [options] [revs] [--] [paths] or: tig log [options] [revs] [--] [paths] or: tig show [options] [revs] [--] [paths] or: tig blame [options] [rev] [--] path
or: tig grep [options] [pattern] or: tig stash
or: tig status
or: tig < [git command output]
+ Select line in the first view
-v, --version Show version and exit
-h, --help Show help message and exit
You can also use 'man' command to read all about its manual pages.
# man tig
Tig is basically a viewer for the state of your repo at various points in time, but it can also enhance your Git workflow by helping you view diffs and commit history, manage branches, and even make edits and commit them by integrating with your text editor. As you know Git is a powerful tool for making snapshots of your code, but it’s also difficult to learn and use. That's why Tig helps, with its powerful views and key bindings that makes it much more manageable. It has fundamentally changed the way that we use Git which definitely make the way more efficient for us.