The add command marks changes to be included in the next commit. It adds changes to “Staging Area”, the contents of which can then be wrapped up in a new revision with the git commit command. However, git add doesn’t really affect the repository in any significant way—changes are not actually recorded until you run git commit.

Staging lets you group related changes into focused snapshots before actually committing it to the project history. This means you can make all sorts of edits to unrelated files, then go back and split them up into logical commits by adding related changes to the stage and commit them piece-by-piece.

Examples

  • Adding one or multiple paths and thereby add changes in these files to the Staging Area
    git add a.html b.html
  • Stage all changes in directory for the next commit
    git add <directory>
  • Add all current modifications in your project to be added to the Staging Area including deletions and new files
    git add --all
    git add -A
  • Stages new files and modifications, without deletions
    git add .
  • Stages modifications and deletions, without new files
    git add -u
  • For interactive staging session that lets you choose portions of a file to add to the next commit. Use y to stage the chunk, n to ignore the chunk, s to split it into smaller chunks, e to manually edit the chunk, and q to exit.
    git add -p