Skip to content

git add

Overview

git add is the command to Add files to the staging area

The stage of file included: untracked, modified, deleted.

The diagram described the flow of files in the staging area

graph LR
  A[Untracked] --> B[Modified]
  B --> C[Deleted]
  C --> B
  B --> A
  A --> D[Staging Area]
  B --> D
  C --> D
  style A fill:#f9f,stroke:#333,stroke-width:4px
  style B fill:#ccf,stroke:#333,stroke-width:4px
  style C fill:#ffc,stroke:#333,stroke-width:4px
  style D fill:#ffa,stroke:#333,stroke-width:4px

Usage

The usage for git add

git add -help
usage: git add [<options>] [--] <pathspec>...

    -n, --[no-]dry-run    dry run
    -v, --[no-]verbose    be verbose

    -i, --[no-]interactive
                          interactive picking
    -p, --[no-]patch      select hunks interactively
    -e, --[no-]edit       edit current diff and apply
    -f, --[no-]force      allow adding otherwise ignored files
    -u, --[no-]update     update tracked files
    --[no-]renormalize    renormalize EOL of tracked files (implies -u)
    -N, --[no-]intent-to-add
                          record only the fact that the path will be added later
    -A, --[no-]all        add changes from all tracked and untracked files
    --[no-]ignore-removal ignore paths removed in the working tree (same as --no-all)
    --[no-]refresh        don't add, only refresh the index
    --[no-]ignore-errors  just skip files which cannot be added because of errors
    --[no-]ignore-missing check if - even missing - files are ignored in dry run
    --[no-]sparse         allow updating entries outside of the sparse-checkout cone
    --[no-]chmod (+|-)x   override the executable bit of the listed files
    --[no-]pathspec-from-file <file>
                          read pathspec from file
    --[no-]pathspec-file-nul
                          with --pathspec-from-file, pathspec elements are separated with NUL character

Commands

Command Description
git add <path> Add specific file path
git add -u Stage modified and deleted files only
git add . Stage modified, deleted, and new files
git add -A Stage everything (modified, deleted, new)
git add -p Stage hunks interactively

Examples

For interactive mode

$ git add -i
           staged     unstaged path
  1:    unchanged        +0/-2 TODO.Md
  2:    unchanged       +15/-0 docs/cookbook/python/polars.md
  3:    unchanged       +33/-2 docs/technology/tool/jq.md
  4:    unchanged        +3/-1 docs/technology/tool/yq.md
  5:    unchanged        +0/-1 mkdocs.yml

*** Commands ***
  1: status       2: update       3: revert       4: add untracked
  5: patch        6: diff         7: quit         8: help