tig - improving git productivity
Hello! I want to talk about the console utility, which significantly increased my productivity with Git, and, I hope, will speed up yours as well. It is called tig and was written by Canadian programmer Jonas Fonseca back in 2006, but to this day it is actively developing and maintained in excellent condition. I want to show its functionality (attention, there are relatively heavy gifs inside) and share the most convenient ways to use it.
Despite the abundance of visual GUIs for working with git, many developers still prefer to work in the console. There are many tools in git to increase productivity - aliases, auto-completion, automatic error correction, etc., but still many ordinary actions, such as navigating through the history of commits, analyzing diffs, viewing git blame, and so on - take a decent amount of time and not always convenient.
Installation
Installation is described in detail in the documentation on the main page of the project.
If you work on MacOS, then it tig
is available through Homebrew:
brew install tig
On Linux, it is also available for all major repositories:
apt-get install tig
yum install tig
For other options, the standard scheme is to download the source code (from releases or through git clone
and execute make && make install
. This is described in detail in the link above.
Using
Here is a short demo of what the interface looks like when you run a command tig
from the repository directory:
In general, as one expects from a graphical (albeit text) interface, but the use of the program is quite intuitive, but for starters you need to learn a few basic keyboard shortcuts on which all work with the program is based.
The main key is - h
: show the help window :)
As you can see, there are several views — the main one, the diff view mode, the log mode, the file tree view mode, the blame mode, the current status view, etc.
Switching between all these modes is quite simple, usually it’s enough with the arrows (or j
/ k
) to select the desired log entry or file and press Enter
, or, as, for example, in the case with blame
- the corresponding key ( b
).
Modes are displayed either full screen or in dual-split mode. The latter can be either horizontal or vertical - the program itself will select it depending on the aspect ratio of the terminal, and can update on the fly. To close the current mode (and return to the previous one) - just press q
(quit). To, on the contrary, expand the window with the current mode to full screen - O
. Switch between dual-split modes Tab
.
In view mode, it is diff
very convenient to increase the number of lines above and below the changed line with [
and ]
(decrease and increase, respectively):
The program also has the function of searching through files ( g
- grep
), searching in a window ( /
), opening a file in an external editor ( e
) and, in general, the interface will be especially comfortable for those who are familiar with vim
. For example, with the help :
you can enter various commands, go to the desired line, etc.
Drop-in git replacement
For some teams, it tig
can work as a drop-in replacement git
.
tig status
tig log
tig show
tig blame file
tig grep pattern
tig refs
tig stash
tig status
Also, in pager mode:
git show | tig
Configuration
tig
quite flexible in terms of configuration - it has a configuration file (the path to which can also be configured via TIGRC_USER) - ~/.tigrc
and readline support.
You can create your own teams. For example, the following command copies the commit ID to the clipboard on MacOS X:
bind generic 5 !@sh -c "echo %(commit) | pbcopy"
The project has excellent documentation , more about the expansion of functionality can be found in it.
Conclusion
tig
this is one of those utilities that have greatly accelerated my daily git productivity. Without switching between windows, from the terminal you get a very convenient and intuitive interface for quick navigation through the history and changes of your git repository.
The program is written in C and works incredibly fast, which is always nice, especially on large repositories.