🖥️

LazyGit Workflow and Integration

Oct 17, 2025,

Overview

This lecture introduces LazyGit, a simple and user-friendly terminal interface for Git. It covers installation, key features, navigation, and demonstrates how to integrate LazyGit with Neovim for a more efficient development workflow.

Installation & Setup

  • Install LazyGit:
    • On Mac, use Homebrew for installation:
      brew install lazygit
      
    • On Linux or Windows, follow the installation instructions in the official repository for your operating system.
  • Verify Installation:
    lazygit --version
    
    • This command checks if LazyGit is installed correctly.
  • Launching LazyGit:
    • Navigate to your Git repository in the terminal:
      cd path/to/your/repo
      
    • Start LazyGit:
      lazygit
      

LazyGit Interface & Navigation

  • UI Layout:
    • The interface is divided into numbered panes (e.g., files, branches, commits).
    • Switch between panes using:
      • Number keys (e.g., 2 for files, 4 for commits)
      • Tab to move forward, Shift+Tab to move backward
  • Within Panes:
    • Move up/down using arrow keys or j/k (Vim-style).
    • Cycle through tabs in a pane with ] (next) and [ (previous).
  • Preview Changes:
    • The right panel shows diffs for selected files.
    • Scroll diffs with Page Up/Page Down or your mouse.
  • Exit LazyGit:
    • Press Ctrl+C to quit.

Staging & Committing Changes

  • Detecting Changes:
    • Modified files are marked with an M.
    • Example: After editing a file and saving changes, reopen LazyGit to see the modification.
  • Staging Files:
    • Select a file and press Space to stage or unstage it.
    • Stage all changes at once with a.
    • Example:
      # Stage a single file
      [select file] → Space
      
      # Stage all files
      a
      
  • Staging Hunks:
    • Press Enter on a file to open a split view of changes.
    • Use arrow keys or j/k to select a hunk, then press Space to stage/unstage.
    • To unstage, move to the staged side with Tab and press Space.
  • Committing:
    • After staging, press C to start a commit.
    • Enter a commit message, press Tab to add a description, then Enter to confirm.
    • Example:
      C
      [Type commit message]
      Tab
      [Type description]
      Tab
      Enter
      

Branching & Merging

  • Viewing and Switching Branches:
    • Go to pane 3 (branches) by pressing 3.
    • The current branch is marked with *.
    • Use j/k or arrow keys to select a branch, then Space to switch.
  • Creating a New Branch:
    • Press n, type the new branch name, and press Enter.
    • Example:
      n
      example-feature-branch
      Enter
      
  • Merging Branches:
    • In the branch pane, select the branch to merge into the current one.
    • Press Shift+M (capital M) and Enter to merge.
  • Resolving Merge Conflicts:
    • If a conflict occurs, press Enter on the conflicted file.
    • Use j/k to navigate hunks, Space to select the desired hunk, or B to pick all hunks.
    • After resolving, press Enter to finish.
    • Example:
      [On conflicted file] → Enter
      [Select hunk] → Space
      Enter
      

Remote Operations

  • Pushing Changes:
    • Press ? to open key bindings, then search for "push" with /.
    • Use P (Shift+P) to push commits to the remote repository.
    • Example:
      P
      
  • Viewing Commits:
    • Go to pane 4 (commits) by pressing 4.
    • Select a commit and press Enter to view its details and changed files.
    • Press Escape to return.

Navigation Shortcuts & Search

  • Key Bindings:
    • Press ? to view all available shortcuts for the current pane.
  • Filtering:
    • Use / to filter key bindings, branches, or commits.
    • Example: /stage to find staging shortcuts.
  • Exiting Modes:
    • Press Escape to exit search or filter modes.

Integration with Neovim

  • Adding LazyGit Plugin:
    • In your Neovim config (e.g., ~/.config/nvim/lua/plugins.lua), add:
      use {
        'kdheepak/lazygit.nvim',
        requires = { 'nvim-lua/plenary.nvim' }
      }
      
  • Key Mapping:
    • Register a key mapping to open LazyGit, for example:
      vim.api.nvim_set_keymap('n', '<leader>lg', ':LazyGit<CR>', { noremap = true, silent = true })
      
      • <leader> is usually mapped to Space, so Space+lg opens LazyGit.
  • Using LazyGit in Neovim:
    • Open Neovim in your project directory.
    • Press your mapped key (e.g., Space+lg) to launch LazyGit inside Neovim.
    • Close LazyGit with q or Ctrl+C.

Key Terms & Definitions

  • LazyGit — A terminal UI for Git that simplifies version control tasks.
  • Pane — A section of the LazyGit interface (e.g., files, branches, commits).
  • Staging — Selecting changes to include in the next commit.
  • Hunk — A contiguous block of changed lines in a file.
  • Merge Conflict — When changes in two branches overlap and must be resolved manually.

Action Items / Next Steps

  • Install LazyGit using the instructions for your operating system.
  • Practice navigating the UI, staging files and hunks, committing, and merging branches.
  • Integrate LazyGit into Neovim by updating your configuration and adding the plugin.
  • Use ? and / frequently to discover shortcuts and filter actions.
  • Experiment with resolving merge conflicts and pushing changes to remote repositories.