Git Integration in LazyVim
Git Integration in LazyVim
LazyVim provides seamless git integration through LazyGit and Gitsigns. You can stage hunks, commit, push, browse history, and resolve conflicts without leaving your editor.
LazyGit - Visual Git Interface
LazyGit is a terminal UI for git that integrates perfectly with LazyVim.
Open LazyGit
Space + g + g
This opens a full-screen git interface inside Neovim.
LazyGit Interface
βββββββββββββββββββββββββββββββββββββββββββ
β Status β Files β Branches β ... β
βββββββββββββββββββββββββββββββββββββββββββ€
β Modified files: β
β src/App.tsx β
β src/utils/helper.ts β
β β
β Staged files: β
β README.md β
βββββββββββββββββββββββββββββββββββββββββββ
LazyGit Keybindings
Navigation:
j/k- Move down/uph/l- Move between panelsTab- Next panelShift+Tab- Previous panel
File Operations:
Space- Stage/unstage filea- Stage all filesA- Unstage all filesd- Discard changes (careful!)e- Edit file in NeovimEnter- View file diff
Commits:
c- Commit staged filesC- Commit using git editorShift+W- Commit without pre-commit hooks
Branches:
n- Create new branchSpace- Checkout branchM- Merge branchr- Rebase branchd- Delete branch
Remote:
p- PullP- PushShift+P- Push with force
History:
Shift+L- View logsEnteron commit - View commit detailsw- Open commit in browser (if GitHub)
Exit:
q- Quit LazyGitEsc- Go back/cancel
Gitsigns - Inline Git Changes
Gitsigns shows git changes directly in your editor with inline diff markers.
Git Signs in Editor
LazyVim shows changes in the sign column (left of line numbers):
β+ Added line
β~ Modified line
β_ Deleted line (shows where it was)
Navigate Changes (Hunks)
]h # Next hunk (change)
[h # Previous hunk (change)
Workflow:
# You're editing a file with multiple changes
]h # Jump to next change
]h # Jump to next change
[h # Go back to previous change
Preview Hunk Diff
Space + g + h
Shows a floating window with the diff of the current hunk.
Example:
diff-const oldValue = 42; +const newValue = 43;
Stage/Unstage Hunks
Space + g + s # Stage hunk
Space + g + u # Unstage hunk
Workflow:
# You have 5 changes in a file
# Only want to commit 2 of them
]h # Jump to first change
Space + g + s # Stage this hunk
]h # Jump to next change
Space + g + s # Stage this hunk
# Other hunks remain unstaged
# Commit only staged hunks
Reset Hunk (Discard Changes)
Space + g + r # Reset hunk (careful!)
Careful: This discards your changes permanently!
Stage Visual Selection
# In visual mode:
V # Select lines
Space + g + s # Stage selected lines only
Use case: Stage only part of a larger change.
Blame Line
Space + g + b # Show git blame for current line
Shows who last modified this line and when.
Example output:
John Doe (2 weeks ago) - feat: add user authentication
Common Workflows
Workflow 1: Quick Commit
Scenario: Changed a few files, want to commit all.
bashSpace + g + g # Open LazyGit a # Stage all files c # Commit # Type message, save and quit P # Push q # Close LazyGit
Workflow 2: Selective Staging
Scenario: Multiple changes in one file, want to commit only some.
bash# In your file with changes ]h # Jump to first hunk Space + g + h # Preview diff Space + g + s # Stage this hunk ]h # Next hunk Space + g + s # Stage this too # Leave other hunks unstaged Space + g + g # Open LazyGit c # Commit staged hunks
Workflow 3: Review Changes Before Commit
Scenario: See all changes before committing.
bashSpace + g + g # Open LazyGit # Navigate to file Enter # View full diff # Review changes Esc # Back to file list Space # Stage file c # Commit
Workflow 4: Amend Last Commit
Scenario: Forgot to include a change in last commit.
bash# Make your additional changes Space + g + g # Open LazyGit a # Stage all Shift+A # Amend last commit # Edit message if needed # Save and quit Shift+P # Force push (if already pushed)
Workflow 5: Branch and Merge
Scenario: Create feature branch, work, merge back.
bashSpace + g + g # Open LazyGit n # New branch # Type: feature/my-feature # Work on your code... Space + g + g # LazyGit c # Commit P # Push # Switch to main branch Space # (on main branch in list) M # Merge feature branch # Select branch to merge
Workflow 6: Resolve Merge Conflicts
Scenario: Pull has conflicts.
bashSpace + g + g # Open LazyGit p # Pull # Conflict detected! e # Edit conflicted file # In file, you see: <<<<<<< HEAD const value = 1; ======= const value = 2; >>>>>>> branch # Manually resolve conflict # Delete conflict markers # Keep what you want # Back to LazyGit Space + g + g Space # Stage resolved file c # Commit merge
Advanced Features
Interactive Rebase
bashSpace + g + g # LazyGit Shift+L # View log e # Edit commit (starts rebase) # LazyGit guides you through rebase
Use cases:
- Squash commits
- Reword commit messages
- Reorder commits
- Drop commits
Stash Changes
bashSpace + g + g # LazyGit s # Stash changes # Work on something else... g # Pop stash (reapply changes)
Use case: Quickly save work to switch contexts.
Cherry-pick Commits
bashSpace + g + g # LazyGit Shift+L # View log c # Cherry-pick commit # Select target branch
View File History
bash# On a file in LazyGit Shift+L # View file history Enter # View commit
Diff View in Editor
bash:DiffviewOpen # Open diff view :DiffviewClose # Close diff view :DiffviewFileHistory # View file history :DiffviewFileHistory % # History of current file
Git Commands from Command Line
LazyVim has a built-in terminal, so you can still use git CLI:
bashCtrl+\ # Open terminal git status git log --oneline git diff exit # Close terminal
Keybinding Reference
Gitsigns (In Editor)
| Action | Keybinding |
|---|---|
| Next hunk | ]h |
| Previous hunk | [h |
| Preview hunk | Space g h |
| Stage hunk | Space g s |
| Unstage hunk | Space g u |
| Reset hunk | Space g r |
| Blame line | Space g b |
LazyGit
| Action | Keybinding |
|---|---|
| Open LazyGit | Space g g |
| Stage file | Space |
| Stage all | a |
| Unstage all | A |
| Commit | c |
| Amend | Shift+A |
| Push | P |
| Pull | p |
| New branch | n |
| Merge | M |
| Rebase | r |
| Logs | Shift+L |
| Stash | s |
| Quit | q |
Tips and Tricks
1. Use hunks for atomic commits
- Stage individual changes with
Space g s - Commit only related changes together
- Makes git history cleaner
2. Preview before staging
- Always use
Space g hto preview hunk - Verify you're staging the right change
3. Blame for context
- Use
Space g bto see who wrote a line - Helpful for understanding why code exists
4. LazyGit is faster than CLI
- Visual interface is quicker for reviewing changes
- Staging/unstaging is one keypress
5. Learn rebase in LazyGit
- Interactive rebase is easier in LazyGit than CLI
- Use it to clean up commit history before PRs
6. Terminal for complex git
- Ctrl+\ opens terminal in Neovim
- Use CLI for advanced git operations
Common Mistakes
β Staging entire files with big changes
β Use hunk staging (Space g s) for granular commits
β Committing without reviewing diff
β Always preview with Enter in LazyGit or Space g h
β Force pushing without checking
β Double-check branch before Shift+P
β Not using blame
β Space g b gives context about why code exists
β Ignoring stash
β Use stash (s in LazyGit) when switching contexts
Integration with GitHub/GitLab
LazyGit can open commits in your browser:
bash# In LazyGit, on a commit w # Open in web browser
For this to work:
- Repo must have a remote on GitHub/GitLab
- Remote must be named
origin
Troubleshooting
LazyGit not opening:
bash# Install lazygit brew install lazygit # Restart Neovim
Git signs not showing:
vim:Gitsigns toggle_signs
Merge conflicts not detected:
vim:Gitsigns setqflist all
Related:
- File Navigation in LazyVim - Finding files to edit
- Code Editing Workflows - Making the changes
- LSP and Code Intelligence - Code refactoring
- Neovim - The Vim Ecosystem - Understanding the editor