Overview
LazyGit is a simple terminal UI for git commands that integrates seamlessly with Neovim. The Magictt config provides easy access to LazyGit’s powerful interface for managing git operations without leaving your editor.
What LazyGit Does
- Git Interface: Full-featured git UI in a terminal window
- Visual Git Operations: Stage, commit, push, pull, and more with keyboard shortcuts
- Branch Management: Create, switch, merge, and rebase branches visually
- Commit History: Browse and search through commit history
- Diff Viewing: View file changes with syntax highlighting
- Conflict Resolution: Handle merge conflicts interactively
Configuration
The LazyGit plugin configuration:
return {
"kdheepak/lazygit.nvim",
lazy = true,
cmd = {
"LazyGit",
"LazyGitConfig",
"LazyGitCurrentFile",
"LazyGitFilter",
"LazyGitFilterCurrentFile",
},
-- optional for floating window border decoration
dependencies = {
"nvim-lua/plenary.nvim",
},
-- setting the keybinding for LazyGit with 'keys' is recommended in
-- order to load the plugin when the command is run for the first time
keys = {
{ "<leader>ll", "<cmd>LazyGit<cr>", desc = "LazyGit" }
}
}
Source: lua/magictt/plugins/lazygit.lua:1-22
Plugin Features
Lazy Loading
The plugin is lazy-loaded, meaning:
- Doesn’t load on Neovim startup
- Only loads when you first use a LazyGit command
- Improves startup time
- No performance impact until needed
Available Commands
cmd = {
"LazyGit",
"LazyGitConfig",
"LazyGitCurrentFile",
"LazyGitFilter",
"LazyGitFilterCurrentFile",
}
These commands trigger plugin loading:
| Command | Description |
|---|
:LazyGit | Open LazyGit in a floating window |
:LazyGitConfig | Open LazyGit configuration |
:LazyGitCurrentFile | Open LazyGit focused on current file |
:LazyGitFilter | Open LazyGit with commit filter |
:LazyGitFilterCurrentFile | Filter commits for current file |
Dependencies
dependencies = {
"nvim-lua/plenary.nvim",
}
Requires plenary.nvim for:
- Floating window management
- Border decoration
- Utility functions
Keybindings
Neovim Keybinding
| Key | Action | Description |
|---|
<leader>ll | Open LazyGit | Opens LazyGit interface in floating window |
Source: lua/magictt/plugins/lazygit.lua:19
The <leader>l prefix opens the “Lazy panels” menu in which-key, where you can access LazyGit.
LazyGit Interface Keybindings
Once inside LazyGit, these keybindings are available:
Navigation
| Key | Action |
|---|
j/k | Move down/up |
h/l | Move between panels |
[/] | Previous/next tab |
< / > | Scroll left/right |
PgUp/PgDn | Scroll page up/down |
Files Panel
| Key | Action |
|---|
<space> | Stage/unstage file |
a | Stage/unstage all files |
d | View diff options |
D | Reset (discard changes) |
e | Edit file |
o | Open file |
c | Commit changes |
C | Commit using git commit editor |
A | Amend last commit |
Commits Panel
| Key | Action |
|---|
<enter> | View commit files |
c | Checkout commit |
C | Copy commit SHA |
r | Rebase |
R | Rename commit |
d | Delete commit |
s | Squash commit |
f | Fixup commit |
t | Revert commit |
T | Tag commit |
Branches Panel
| Key | Action |
|---|
<space> | Checkout branch |
n | New branch |
d | Delete branch |
D | Force delete branch |
r | Rebase branch |
M | Merge branch |
f | Fast-forward branch |
F | Create pull request |
Stash Panel
| Key | Action |
|---|
<space> | Apply stash |
g | Pop stash |
d | Drop stash |
Global Commands
| Key | Action |
|---|
? | View help/keybindings |
q | Quit LazyGit |
<esc> | Cancel/go back |
P | Push to remote |
p | Pull from remote |
R | Refresh |
: | Execute custom command |
w | Open worktree menu |
Usage
Opening LazyGit
- Press
<leader>ll in Neovim
- LazyGit opens in a floating window
- Use
h/j/k/l to navigate
- Press
? to see all keybindings
Basic Git Workflow
Staging and Committing
- Open LazyGit:
<leader>ll
- View changed files: Files panel shows modified files
- Stage files:
- Navigate to file with
j/k
- Press
<space> to stage
- Or press
a to stage all
- Commit:
- Press
c to commit
- Type commit message
- Press
<enter> to confirm
- Push: Press
P to push to remote
Working with Branches
- View branches: Press
[ or ] to navigate to branches tab
- Create branch: Press
n, type name, press <enter>
- Switch branch: Navigate to branch, press
<space>
- Merge branch: Navigate to branch, press
M
- Delete branch: Navigate to branch, press
d
Viewing History
- View commits: Navigate to commits tab with
[/]
- View commit details: Press
<enter> on a commit
- View file changes: Navigate through changed files
- Copy commit SHA: Press
C on a commit
Handling Conflicts
- When conflicts occur: LazyGit highlights conflicted files
- Navigate to file: Use
j/k to select conflicted file
- Open editor: Press
e to edit in Neovim
- Resolve conflicts: Edit file manually
- Stage resolved file: Return to LazyGit, press
<space> on file
- Continue merge/rebase: Follow prompts
Advanced Operations
Interactive Rebase
- Navigate to commits tab
- Press
r on the base commit
- Select commits to rebase
- Choose actions (squash, fixup, reword, etc.)
- Follow prompts to complete rebase
Stashing Changes
- In files panel, press
s to stash
- Navigate to stash tab with
[/]
- Press
<space> to apply stash
- Press
g to pop stash (apply and delete)
Cherry-picking
- Navigate to commits tab
- Select commit with
j/k
- Press
c to copy commit
- Navigate to target branch
- Press
v to paste (cherry-pick)
Commands Reference
:LazyGit
Opens LazyGit in a floating window:
Or use the keybinding: <leader>ll
:LazyGitCurrentFile
Opens LazyGit focused on the current file’s history:
Useful for:
- Viewing file-specific commit history
- Seeing who changed a file
- Tracking file evolution
:LazyGitFilter
Opens LazyGit with a commit filter:
Enter a filter pattern to search commits by:
- Commit message
- Author
- Date range
- File changes
:LazyGitFilterCurrentFile
Filters commits to show only those affecting the current file:
:LazyGitFilterCurrentFile
Combines filter and current file focus.
:LazyGitConfig
Opens LazyGit configuration file:
Allows customizing LazyGit settings:
- Color scheme
- Keybindings
- UI preferences
- Git command aliases
Tips and Tricks
Quick Commit and Push
<leader>ll - Open LazyGit
a - Stage all files
c - Commit
- Type message and
<enter>
P - Push
q - Quit back to Neovim
Amending Last Commit
- Make changes in Neovim
<leader>ll - Open LazyGit
a - Stage changes
A - Amend commit (capital A)
- Edit message if needed
<enter> - Confirm
Viewing File History
- Open the file you want to investigate
:LazyGitCurrentFile
- Browse commits affecting this file
- Press
<enter> on a commit to see changes
Undoing Last Commit
<leader>ll - Open LazyGit
- Navigate to commits tab
- Select the commit to undo
- Press
t to revert
- Or press
d to delete (if not pushed)
Interactive Staging
To stage parts of a file:
<leader>ll - Open LazyGit
- Navigate to file
- Press
d for diff options
- Press
<enter> to open in patch mode
- Select hunks to stage with
<space>
Working with Remotes
- Press
f to fetch from all remotes
- Press
p to pull from current remote
- Press
P to push to current remote
- Press
<shift-P> for push options (force, set upstream, etc.)
Customization
LazyGit Config Location
LazyGit configuration is separate from Neovim:
- Linux/Mac:
~/.config/lazygit/config.yml
- Windows:
%APPDATA%\lazygit\config.yml
Access with :LazyGitConfig
Custom Colors
Edit LazyGit config to match your Neovim theme:
gui:
theme:
activeBorderColor:
- '#ff9e64'
- bold
inactiveBorderColor:
- '#a9b1d6'
selectedLineBgColor:
- '#364A82'
Custom Keybindings
Add custom keybindings in LazyGit config:
keybinding:
universal:
quit: 'q'
return: 'esc'
files:
commitChanges: 'c'
amendLastCommit: 'A'
Window Size
The plugin uses a floating window by default. To customize the window size, you would need to modify the plugin configuration (not shown in the current config).
Troubleshooting
LazyGit Not Opening
If LazyGit doesn’t open:
-
Check if lazygit is installed:
-
Install lazygit if missing:
- Mac:
brew install lazygit
- Linux:
sudo pacman -S lazygit or equivalent
- Windows:
choco install lazygit
-
Verify plugin is loaded:
Look for lazygit.nvim
Keybinding Not Working
If <leader>ll doesn’t work:
- Check which-key is configured properly
- Verify the keybinding in
lua/magictt/plugins/lazygit.lua:19
- Try the command directly:
:LazyGit
Display Issues
If LazyGit looks broken:
- Ensure your terminal supports colors:
- Use a terminal with full color support (xterm-256color)
- Check LazyGit config for color settings
Git Not Found
If you get a “git not found” error:
- Ensure git is installed:
- Add git to your PATH
- Restart Neovim
- Which-key - Keybinding reference for
<leader>l group
- Telescope - Alternative for finding commits and files
External Resources