LazyGit Terminal UI

LazyGit cheatsheet — stage, commit, push, rebase, stash with keyboard shortcuts. space=stage, c=commit, P=push, r=rebase. Full LazyGit TUI keyboard reference.

6 min read

What it is

LazyGit is a terminal UI for Git that helps you visualize and interact with your Git repository, making common Git operations faster and more intuitive.

Installation

Linux

# Using apt (Debian/Ubuntu)
sudo apt update
sudo apt install lazygit

# Using dnf (Fedora)
sudo dnf install lazygit

# Using pacman (Arch Linux)
sudo pacman -S lazygit

# Using Homebrew (if installed)
brew install lazygit

Mac

# Using Homebrew
brew install lazygit

Windows

# Using Chocolatey
choco install lazygit

# Using Scoop
scoop install lazygit

# Using Winget
winget install jesseduffield.lazygit

Core Concepts

  • Files Panel: Shows the status of files in your working directory (new, modified, staged, ignored).
  • Commits Panel: Displays the Git commit history for the current branch.
  • Stash Panel: Lists stashed changes.
  • Branches Panel: Shows local and remote branches.
  • Remote Panel: Lists configured remotes and their status.
  • Submodules Panel: Manages Git submodules.

Commands / Usage

LazyGit is interactive. Once launched, you navigate and perform actions using keyboard shortcuts. The primary navigation is between panels using Tab and Shift+Tab. Within panels, arrow keys are used for selection.

Launching LazyGit

# Navigate to your Git repository and run
lazygit
  • Tab: Move to the next panel (Files -> Commits -> Branches -> Stash -> Remotes -> Submodules).
  • Shift+Tab: Move to the previous panel.

Files Panel Actions

  • Space: Stage or unstage a file.
  • Enter: View diff of a selected file.
  • d: Discard changes in a selected file.
  • c: Create a commit from staged changes.
  • a: Stage all modified files.
  • r: Rename a selected file.
  • e: Edit a selected file.
  • s: Split a selected file (useful for staging parts of a file).
  • i: Ignore a selected file.
  • f: Force-add a selected file (stages untracked files).
  • x: Remove a selected file.
  • D: Discard all changes in the repository.

Commits Panel Actions

  • Enter: View the diff of a selected commit.
  • y: Copy commit hash of a selected commit.
  • r: Rename a selected commit.
  • e: Edit a selected commit (opens in editor).
  • d: Revert a selected commit.
  • m: Squash commit(s) into the previous one.
  • p: Pick commit(s) (used for interactive rebase).
  • s: Squash commit(s) (used for interactive rebase).
  • f: Fixup commit(s) (used for interactive rebase).
  • a: Abort an ongoing interactive rebase.
  • c: Continue an ongoing interactive rebase.
  • q: Quit the commit view.
  • j: Move to the next commit.
  • k: Move to the previous commit.

Stash Panel Actions

  • a: Stash all changes.
  • s: Stash selected changes (only staged or unstaged).
  • Pop: Pop a stash.
  • Apply: Apply a stash.
  • Drop: Drop a stash.
  • x: Clear all stashes.

Branches Panel Actions

  • n: Create a new branch.
  • d: Delete a selected branch.
  • D: Force delete a selected branch.
  • r: Rename a selected branch.
  • b: Checkout a selected branch.
  • f: Force checkout a selected branch.
  • p: Push a selected branch.
  • P: Force push a selected branch.
  • pull: Pull changes for a selected branch.
  • M: Merge a selected branch into the current branch.
  • R: Rebase the current branch onto a selected branch.
  • t: Track a remote branch.

Remotes Panel Actions

  • n: Add a new remote.
  • d: Remove a selected remote.
  • r: Rename a selected remote.
  • p: Push to a selected remote.
  • P: Force push to a selected remote.
  • pull: Pull from a selected remote.

Submodules Panel Actions

  • a: Add a submodule.
  • u: Update all submodules.
  • r: Remove a submodule.
  • i: Initialize submodules.

General Commands (Accessible via ? or g)

  • ?: Open help panel.
  • g: Open main menu (includes Git log, stash, rebase, etc.).
  • q: Quit LazyGit.
  • esc: Go back or close current view.

Common Patterns

Staging and Committing

  1. Stage all changes and commit:

    # In LazyGit:
    # Press 'a' in the Files panel to stage all.
    # Press 'c' to commit.
    
  2. Stage specific files and commit:

    # In LazyGit:
    # Navigate to Files panel.
    # Use arrow keys to select files.
    # Press 'Space' to stage/unstage each file.
    # Press 'c' to commit.
    
  3. Stage parts of a file and commit:

    # In LazyGit:
    # Navigate to Files panel.
    # Select the file with modifications.
    # Press 's' to split the file.
    # Use arrow keys and 'Space' to stage/unstage hunks.
    # Press 'Enter' to go back to the Files panel.
    # Press 'c' to commit.
    

Branching and Merging

  1. Create and switch to a new branch:

    # In LazyGit:
    # Navigate to Branches panel.
    # Press 'n'.
    # Type the new branch name (e.g., feature/my-new-feature).
    # Press Enter.
    
  2. Merge develop into main:

    # In LazyGit:
    # Ensure you are on the 'main' branch (checkout if not).
    # Navigate to Branches panel.
    # Select the 'develop' branch.
    # Press 'M' to merge.
    
  3. Rebase main onto feature/my-branch:

    # In LazyGit:
    # Ensure you are on the 'main' branch.
    # Navigate to Branches panel.
    # Select the 'feature/my-branch' branch.
    # Press 'R' to rebase 'main' onto 'feature/my-branch'.
    

Pushing and Pulling

  1. Push current branch to its upstream:

    # In LazyGit:
    # Navigate to Branches panel.
    # Select the branch you want to push.
    # Press 'p'.
    
  2. Pull changes for the current branch:

    # In LazyGit:
    # Navigate to Branches panel.
    # Select the branch you want to pull.
    # Press 'pull'.
    
  3. Push all branches (less common, use with caution):

    # In LazyGit:
    # Press 'g' to open the main menu.
    # Navigate to 'Remotes'.
    # Select 'Push All Branches'.
    

Rebasing Interactively

  1. Reorder, squash, or edit commits:
    # In LazyGit:
    # Ensure you are on the branch you want to rebase.
    # Press 'g' to open the main menu.
    # Navigate to 'Interactive Rebase'.
    # Select the branch you want to rebase onto (e.g., main).
    # Press Enter.
    # In the rebase view:
    #   - Use arrow keys to select commits.
    #   - Press 'p' (pick), 's' (squash), 'f' (fixup), 'e' (edit).
    #   - Use arrow keys to move commits up/down.
    #   - Press 'c' to continue the rebase.
    #   - Press 'a' to abort the rebase.
    

Handling Stashes

  1. Stash all changes:

    # In LazyGit:
    # Navigate to Stash panel.
    # Press 'a'.
    
  2. Apply a stash:

    # In LazyGit:
    # Navigate to Stash panel.
    # Select the stash.
    # Press 'Apply'.
    
  3. Drop a stash:

    # In LazyGit:
    # Navigate to Stash panel.
    # Select the stash.
    # Press 'Drop'.
    

Gotchas

  • Confusing Interactive Rebase Actions: The keys for interactive rebase (p, s, f, e) might seem counter-intuitive at first. p is for "pick", s is for "squash" (combine with previous commit, edit message), f is for "fixup" (combine with previous commit, discard message), e is for "edit" (stop and edit the commit).
  • Force Push (P): Be extremely cautious with force pushing, especially on shared branches. It overwrites history and can cause major problems for collaborators.
  • Discarding Changes (d): This action is irreversible for the selected file(s). Ensure you don’t need the changes before discarding.
  • Renaming Commits (r in Commits Panel): This action renames the commit message. It’s different from editing the commit content.
  • Reverting Commits (d in Commits Panel): This creates a new commit that undoes the changes introduced by the selected commit. It does not delete the original commit.
  • Initial Setup: If you are in a directory that is not a Git repository, LazyGit will prompt you to initialize one.
  • Keybindings Customization: LazyGit’s keybindings can be customized in its configuration file (~/.config/lazygit/config.yml). This can be useful if the default bindings conflict with other tools or your preferences.