Tig (Text-mode Interface for Git) Cheatsheet¶
Installation¶
| Platform | Command |
|---|---|
| Ubuntu/Debian | sudo apt update && sudo apt install tig |
| Fedora/RHEL | sudo dnf install tig |
| Arch Linux | sudo pacman -S tig |
| macOS (Homebrew) | brew install tig |
| macOS (MacPorts) | sudo port install tig |
| Windows (Git Bash) | Included with Git for Windows |
| Windows (WSL) | sudo apt install tig |
| Windows (Scoop) | scoop install tig |
| From Source | git clone https://github.com/jonas/tig.git && cd tig && make && sudo make install |
Verify Installation: tig --version
Basic Commands¶
| Command | Description |
|---|---|
tig |
Open main view showing commit history in current repository |
tig status |
Show working directory status (like git status) |
tig blame <file> |
Show line-by-line authorship for a file |
tig <file> |
Show commit history for a specific file |
tig show <commit> |
Display details of a specific commit |
tig refs |
Show all branches and tags |
tig stash |
Display all stashed changes |
tig log |
Show commit log view |
tig diff |
Show unstaged changes in working directory |
tig grep <pattern> |
Search for pattern in repository |
tig <branch> |
Show commits from a specific branch |
tig --all |
Show commits from all branches |
tig --help |
Display help information |
tig --version |
Show tig version information |
Navigation Keys (Inside Tig)¶
| Key | Description |
|---|---|
j / ↓ |
Move down one line |
k / ↑ |
Move up one line |
h / ← |
Scroll left |
l / → |
Scroll right |
PgUp / b |
Page up |
PgDn / Space |
Page down |
Home |
Jump to first line |
End |
Jump to last line |
Enter |
Open/select item (context-dependent) |
Tab |
Switch to next view |
q |
Close current view |
Q |
Close all views and quit |
R |
Reload/refresh current view |
O |
Maximize current view |
h |
Show help and key bindings |
Search and Filter Keys¶
| Key | Description |
|---|---|
/ |
Search forward |
? |
Search backward |
n |
Find next match |
N |
Find previous match |
[ |
Jump to previous diff chunk |
] |
Jump to next diff chunk |
{ |
Jump to previous file in diff |
} |
Jump to next file in diff |
Advanced Commands¶
| Command | Description |
|---|---|
tig --author="Name" |
Filter commits by specific author |
tig --since="2 weeks ago" |
Show commits from a relative date |
tig --after="2024-01-01" --before="2024-12-31" |
Show commits within date range |
tig --grep="pattern" |
Show commits with pattern in message |
tig --merges |
Show only merge commits |
tig --no-merges |
Exclude merge commits |
tig main..feature |
Show commits in feature not in main |
tig main...feature |
Show commits that differ between branches |
tig --follow -- <file> |
Track file history through renames |
tig -S"function_name" |
Pickaxe search: commits changing occurrences |
tig -G"regex" |
Show commits where diff matches regex |
tig -n 100 |
Limit to last 100 commits |
tig -- '*.py' |
Show commits affecting Python files only |
tig reflog |
Browse Git reflog entries |
tig show <commit>:<path> |
Display file content at specific commit |
tig blame +<line> <file> |
Open blame view at specific line number |
Interactive Operations (Inside Tig)¶
| Key | View | Description |
|---|---|---|
u |
status | Stage/unstage file or chunk |
1 |
status | Stage/unstage single line |
! |
status | Revert file or chunk |
C |
status | Commit staged changes |
C |
main/log | Cherry-pick commit |
e |
main/log | Edit commit message (if HEAD) |
! |
main/log | Revert commit |
@ |
main/log | Move to commit (checkout) |
C |
refs | Create new branch |
d |
refs | Delete branch |
m |
refs | Merge branch |
! |
any | Execute external command |
: |
any | Execute git command (e.g., :!git reset) |
Configuration¶
Tig reads configuration from these locations (in priority order):
$XDG_CONFIG_HOME/tig/config(typically~/.config/tig/config)~/.tigrc$GIT_DIR/tigrc(repository-specific)/etc/tigrc(system-wide)
Creating Configuration File¶
# Create user config directory and file
mkdir -p ~/.config/tig
touch ~/.config/tig/config
# Or use traditional location
touch ~/.tigrc
Color Customization¶
# Customize interface colors
color cursor white blue bold
color title-focus white blue bold
color title-blur white black bold
# Diff colors
color diff-header yellow default
color diff-chunk magenta default
color diff-add green default
color diff-del red default
# Status colors
color stat-staged green default
color stat-unstaged red default
color stat-untracked yellow default
View Settings¶
# Configure main view columns
set main-view = id:yes date:default author:full commit-title:yes,graph:yes,refs:yes
# Set commit ID width
set id-width = 10
# Enable line numbers in blame view
set blame-view = date:default author:full id:yes,color line-number:yes,interval=1 text
# Line number display interval
set line-number-interval = 5
# Horizontal scrolling percentage
set horizontal-scroll = 33%
# Tab size for display
set tab-size = 4
# Truncation indicator
set truncation-delimiter = ~
Diff Configuration¶
# Number of context lines in diffs
set diff-context = 3
# Ignore whitespace (options: no, all, some, at-eol)
set ignore-space = some
# Use patience diff algorithm
set diff-options = --patience
# Show untracked files in status view
set status-show-untracked-files = yes
Custom Key Bindings¶
# Bind 'C' in main view to cherry-pick
bind main C !git cherry-pick %(commit)
# Bind 'P' in status view to push
bind status P !git push
# Bind 'F' to fetch in main view
bind main F !git fetch
# Bind 'S' to create stash
bind status S !git stash save "%(prompt Enter stash message: )"
# Bind 'A' to amend commit
bind status A !git commit --amend
# Open commit in browser (GitHub)
bind main B !@hub browse -- commit/%(commit)
Display Options¶
# Wrap long lines
set wrap-lines = yes
# Show changes in status view
set status-show-untracked-dirs = yes
# Refresh interval (seconds)
set refresh-mode = auto
set refresh-interval = 1
# Mouse support
set mouse = yes
# Editor for commit messages
set editor-line-number = yes
Common Use Cases¶
Use Case 1: Code Review Workflow¶
# Open repository
tig
# Navigate to commit (use j/k)
# Press Enter to see full diff
# Press Tab to switch between views
# Press q to go back
# Review specific branch
tig feature-branch
# Compare branches
tig main..feature-branch
Use Case 2: Finding When a Bug Was Introduced¶
# Search for specific code change
tig -S"problematic_function"
# Or search commit messages
tig --grep="bug\|fix" -i
# View blame for specific file
tig blame src/buggy-file.js
# Navigate to suspicious line
# Press Enter to see the commit
# Press Tab to see full commit details
Use Case 3: Interactive Staging and Committing¶
# Open status view
tig status
# Navigate to files (j/k)
# Press 'u' to stage/unstage files
# Press '1' to stage individual lines
# Press 'C' to commit when ready
# Write commit message and save
Use Case 4: Exploring Project History¶
# View all commits with graph
tig --all
# Filter by author and date
tig --author="John Doe" --since="1 month ago"
# View commits affecting specific files
tig -- src/core/*.py
# Follow file through renames
tig --follow -- src/renamed-file.js
Use Case 5: Branch Management¶
# View all branches and tags
tig refs
# Navigate to branch
# Press 'C' to create new branch
# Press 'd' to delete branch
# Press 'm' to merge branch
# Press Enter to view branch commits
Best Practices¶
-
Learn keyboard shortcuts: Tig is designed for keyboard navigation. Memorize
j/kfor movement,Enterto drill down, andqto go back for efficient browsing. -
Use view-specific commands: Different views have different operations. Press
hin any view to see available key bindings for that context. -
Customize your configuration: Create a
~/.config/tig/configfile to customize colors, bindings, and view settings to match your workflow and preferences. -
Combine with Git commands: Use tig for visualization and Git commands for operations. Tig complements Git rather than replacing it.
-
Use filters for large repositories: In repositories with thousands of commits, use
--author,--since,--grep, or file filters to narrow results. -
Leverage the status view: Use
tig statusas an interactive alternative togit add -pfor granular staging control. -
Explore with Tab: Use
Tabto cycle through related views and see different perspectives on the same data (commit → diff → tree). -
Set up repository-specific configs: Create
.git/tigrcin repositories that need special settings without affecting your global configuration.
Troubleshooting¶
| Issue | Solution |
|---|---|
| Tig not found after installation | Ensure tig is in your PATH: which tig. Restart terminal or run source ~/.bashrc |
| Colors not displaying correctly | Check terminal supports 256 colors. Set TERM=xterm-256color or configure colors in ~/.tigrc |
| Slow performance in large repos | Use filters to limit commits: tig -n 1000 or tig --since="1 month ago". Consider set refresh-mode = manual |
| UTF-8 characters display incorrectly | Set locale: export LC_ALL=en_US.UTF-8 and export LANG=en_US.UTF-8 in shell config |
| Mouse not working | Enable in config: set mouse = yes. Ensure terminal supports mouse events |
| Can't edit commits or stage files | Ensure you have write permissions and are in a valid Git repository. Check git status works |
| Custom key bindings not working | Verify syntax in config file. Check for conflicts with default bindings. Reload with R |
| Tig crashes on startup | Check Git repository is valid: git status. Update tig to latest version. Remove custom config temporarily |
| Diff view shows binary files | Add to .gitattributes: *.bin -diff. Or set set diff-options = --no-binary |
| Line numbers not showing | Enable in config: set line-number-interval = 1 and ensure view supports line numbers |
Quick Reference Card¶
LAUNCHING TIG NAVIGATION OPERATIONS
tig j/k ↓/↑ Move u Stage/unstage
tig status h/l ←/→ Scroll C Commit/cherry-pick
tig blame <file> PgUp/PgDn Page ! Revert/execute
tig <branch> Enter Select e Edit
tig --all Tab Next view @ Checkout
q/Q Quit R Refresh
SEARCH VIEWS FILTERS
/ Search forward tig Main --author="Name"
? Search backward tig status Status --since="date"
n Next match tig refs Branches --grep="pattern"
N Previous match tig blame Blame --no-merges
[ Prev chunk tig stash Stash -- '*.ext'
] Next chunk tig diff Diff