Skip to main content

Lazygit

1. Basics

Panel Navigation

  • / (Left/Right Arrow Keys): Navigate between panels in this order:

    • Status panel
    • Files panel (changed, created, or deleted files)
    • Branches panel
    • Commits panel
    • Stash panel
  • Tab / Shift+Tab: Same as above arrows

Pushing / Pulling

  • p: invokes a git pull.
  • Shift+P: invokes a git push
    • When git identifies a divergence, it opens a confirmation box asking whether to push --force or cancel the operation.

Command Prompt

  • :: Opens a command prompt that allows for quickly executing shell commands without having to quit lazygit or switch to a different terminal

Help Menu

  • ?: Opens a menu with all available keybindings and actions. The menu is context-specific, and changes based on the current active panel.

2. Files Panel

Basic File Staging

  • Space: Toggle staging/unstaging of the selected file
  • a: Toggle between staging all files or resetting all files

Committing Changes

  • c: Open the commit message editor to write your commit message

Discarding Changes

  • d: Discard changes on the selected file (shows confirmation box)
  • Shift+D: Open a menu with multiple discard options
    • Nuke working tree: Clears all changes and deletes all new files (most commonly used)

Viewing File Changes

  • Enter: Navigate to the split view showing file changes
    • Left side: unstaged changes
    • Right side: staged changes

Stashing Changes

  • s: Stash changes. Asks for confirmation and an optional name for the stash.
  • Shift+S: Opens a stash options menu where you can choose to stash only staged changes.

3. Files --> Diff View Sub-Panel

When you press Enter on a file, you enter the diff view where you can stage individual lines or hunks.

Staging Modes

  • a: Toggle between two staging modes:
    • Hunk mode: Stage entire hunks (like VS Code's diff viewer)
    • Line mode: Stage individual lines
  • Space: Add or remove the current line/hunk (toggles between staged/unstaged)

Range Selection

  • v: Start selecting a range of lines
  • / (Arrow Keys Up/Down): Extend the selection range
  • Space: Stage or unstage the selected range
  • Tab: Switch from the left pane (unstaged) to the right pane (staged)

Removing Changes

  • d (left pane): Delete the line/change
  • d (right pane): Unstage the change

4. Branches Panel

Switching Branches

  • Space (on a branch): Check out to that branch

Fetching a Branch

  • f (on a branch): Fetch the selected branch

Rebasing

  • r (on a branch): Rebase the current branch (marked with *) onto the selected branch

Creating Pull Requests

  • o: Create a pull request from the currently selected branch
    • The pull request will target the default branch (e.g., main or master)
  • Shift+O: Create a pull request with a target branch selection
    • Opens a searchable dropdown allowing you to choose which branch to merge into

5. Commits Panel

Viewing Commit Files

  • Enter (on a commit): View the actual files that were involved in that commit. By hitting Esc, you can go back to the list of commits.

Resetting to a Commit

  • g (on a commit): Reset to that commit. Opens a menu asking what to do with the changes between HEAD and that commit (discard them or keep them).

Cherry Picking

  1. Navigate to the Commits panel
  2. v: Start range selection mode
  3. / (Arrow Keys Up/Down): Extend the range to select multiple commits
  4. Shift+C: Copy the selected commit hashes
  5. Navigate to the Branches panel
  6. Space: Check out to the target branch
  7. Shift+V: Paste and apply the copied commits (cherry pick)

Amending Commits

  1. Make changes to your file(s)
  2. Navigate to the Commits panel
  3. Select the last commit (the one you want to amend)
  4. Shift+A: Request to amend the commit with your changes
  5. Enter: Confirm and apply the amendment

Squashing Commits

  • s (on a commit): Squash the commit with the commit below it. Asks for confirmation before executing.

Reverting Commits

  • t (on a commit): Revert that commit. Asks for confirmation before execution.

Moving Code Between Commits

To move specific changes from one commit to another:

  1. Select a commit and press Enter on a file to view all changes made to that file
  2. Use Space to extract specific diffs and create a "custom patch" (visible on the right side)
  3. Press Esc twice to return to the commits list
  4. Navigate to the target commit where you want to move the patch
  5. Press Ctrl+P to open the patch menu
  6. Select "move the patch into the selected commit"

6. Quick Reference Table

KeyContextAction
Any panelNavigate between panels
SpaceFiles panelToggle file staging
SpaceDiff viewStage/unstage line or hunk
SpaceBranches panelCheck out branch
aFiles panelToggle stage/unstage all files
aDiff viewToggle hunk/line mode
cFiles panelOpen commit message editor
dFiles panelDiscard file changes
dDiff view (left)Delete line
dDiff view (right)Unstage change
Shift+DFiles panelOpen discard menu
EnterFiles panelView file diff
TabDiff viewSwitch between unstaged/staged panes
vDiff viewStart range selection
vCommits panelStart commit range selection
Shift+CCommits panelCopy selected commits
Shift+VCommits panelPaste/cherry-pick commits
Shift+ACommits panelAmend commit