Skip to content

Staging and Committing

This is the chapter the whole tool is for: turning a pile of changed files into a commit, one deliberate choice at a time. The outcome: you can stage files singly, in a folder, or all at once; read the two status columns as they change; and commit through lazygit's editor — including the day you press the commit key with nothing staged at all.

Work in the fixture repository (chapter 4), on main, with its three waiting changes: shopping.txt already staged, summer-walk.txt modified, winter-walk.txt untracked.

Staging, one file at a time

Select summer-walk.txt with j and k. Its unstaged diff fills the main panel — the added lines about the flask of tea, marked +. That diff is the thing you are being asked to approve; the staging decision in lazygit is always made looking at it.

Press Space. Three things happen (transcript lazygit-lab/transcripts/t02-staging.txt):

  • The file's code changes from M to M — the letter moves from the working-tree column to the staged column. The change now sits in the index, the staging area from which the next commit will be built.
  • The main panel's title changes from Unstaged changes to Staged changes: it is showing you the diff as the index holds it.
  • In the command log, one line appears: git add -- summer-walk.txt. Chapter 1's promise, kept in the corner of the screen — that is all staging ever was.

Space is a toggle: press it again and the file is unstaged, the command log showing the reset that took it back out. Walk to winter-walk.txt and press Space: the untracked file becomes A, added — staging is also how a new file is introduced to git at all. (shopping.txt arrived already staged; its A was there when you opened the program.)

Check, at any point, by quitting (q) and asking git: git status --short shows the same codes in the same columns. Inside lazygit you can also just look: the first column is the truth about the index, always current.

Staging in bulk, and the folder row

Two faster doors, both verified by the lab — one of them by accident.

  • a stages everything — every changed and untracked file, in one press. (In the keybindings list its entry is simply "Stage all".)
  • Space on the folder row stages everything under that folder. The Files panel is a tree, and the root / row is selectable. The lab found this the honest way: intending to stage one file, it pressed Space on the root and watched the whole panel stage at once — command log, git add -- .. On a repository whose files live in real subfolders this is a feature, letting you stage a directory at a time. On the root row it is the same as a, and worth knowing before it surprises you.

The folder row teaches a second lesson: Enter on a folder collapses it. The tree folds to a single row (▶ /, and the panel's border reads "1 of 1"), and Enter opens it again. A Files panel that seems to have lost its files has usually only folded them; chapter 17 returns to this.

The commit editor

With everything you intend staged (the lab staged all three files), press c. A two-box editor opens over the screen (transcript lazygit-lab/transcripts/t03-commit.txt):

  • Commit summary — the commit's subject line, one line, with a counter at the box's corner counting its characters as you type.
  • Commit description — the body, for everything the subject could not hold. Tab moves between the boxes.

Type the summary — the lab used "Add the shopping list and winter stub, note the flask of tea" — and press Enter with the summary focused. The editor closes, the Files panel is empty, and the Commits panel has a new top line with your words in it.

Check: quit and ask git.

git log --oneline -1

The newest commit is yours, word for word. (The lab's full session ended exactly so, with the tree clean — git status had nothing left to say.)

The day nothing is staged

Press c with changes in the tree but nothing in the index and lazygit does not refuse; it asks:

You have not staged any files. Commit all files?

Confirm, and it stages everything itself (the command log shows git add -A) and opens the same editor. Decline with Esc and nothing has happened. This is the program's character in one popup: the shortcut exists, it is offered openly, and the choice stays yours. Chapter 16 notes the one merge-shaped situation where the equivalent question cannot save you — commit is not always the verb you need.

Two neighbours on the same hint bar, for later chapters: A amends the last commit with whatever is staged (chapter 13 opens it up), and C commits through your own configured git editor instead of the built-in boxes, for messages that need a full screen. Both sit in the Files panel's ? list, where the lab read them; the chapters use the built-in editor throughout.

What to commit, and when

The tool makes committing cheap; the habit is still the craft. Commit units that make sense on their own — the walk notes, not the walk notes plus the shopping list plus a fix to the helper — because chapter 7's history is only as readable as the commits you fed it, and chapter 8's undo works one commit at a time. The fixture's ready-made pile is a fine first commit precisely because it is disposable: the repositories that matter deserve the extra ten seconds of choosing.