Git Cheat Sheet · Changes

Stage files

git add <file> · git add -A

Git does not commit your modified files directly: it commits the content of the index, also called the "staging area". git add <file> puts a file in the index. This step lets you split your work into coherent commits.

What it does

Places changes in the index: only what is staged will be part of the next commit.

A use case

You fixed a bug and touched up the docs: you stage the fix first to make it a separate commit.

On the command line

git add <file>
Stages a file, or a whole folder.
git add -A
Stages everything: changes, new files and deletions, across the whole repository.
git add .
Stages everything in the current folder and its subfolders.
git add -u
Stages files already tracked, without new files.
git add '*.css'
Stages all files matching a pattern.

In Merathon

  1. Hover a file in "Unstaged" and click the plus button ("Stage"), or right-click → "Stage".
  2. "Stage all" in the section header takes all files.
  3. Ctrl + click or Shift + click selects several files; in tree view, a folder's "+" stages all its content.

Frequently asked questions

What is the difference between git add . and git add -A?

Since Git 2, both stage additions, changes and deletions. git add . is limited to the current folder, git add -A covers the whole repository.

How do I undo a git add?

git restore --staged <file> removes the file from the index without losing your changes.

See also