LinuxCommandLibrary

git-add

Stage changes for commit

TLDR

Add a file to the index

$ git add [path/to/file]
copy

Add all files (tracked and untracked)
$ git add [[-A|--all]]
copy

Add all files recursively starting from the current folder
$ git add .
copy

Only add already tracked files
$ git add [[-u|--update]]
copy

Also add ignored files
$ git add [[-f|--force]]
copy

Interactively stage parts of files
$ git add [[-p|--patch]]
copy

Interactively stage parts of a given file
$ git add [[-p|--patch]] [path/to/file]
copy

Interactively stage a file
$ git add [[-i|--interactive]]
copy

SYNOPSIS

git add [options] [--] [pathspec]…

PARAMETERS

-A, --all
    Stage all changes: new, modified, deleted files everywhere.

-u, --update
    Stage modified/deleted files only, not new files.

-p, --patch, --interactive
    Interactively select hunks to stage.

-e, --edit
    Edit patches in editor before staging.

-N, --intent-to-add
    Stage file as intent-to-add without content.

--refresh
    Update index from working tree without staging.

--ignore-errors
    Continue on unreadable files.

--ignore-missing
    Ignore pathspecs that do not exist.

-i, --interactive
    Run interactive prompt for staging.

--dry-run
    Show what would be staged without doing it.

-f, --force
    Allow adding ignored files.

--renormalize
    Renormalize stored line endings.

--chmod=(+|-)x
    Override executable bit.

--pathspec-from-file=<file>
    Read pathspecs from file.

--pathspec-file-nul
    Use NUL-terminated paths in file.

DESCRIPTION

The git add command adds file contents to the Git index (staging area), preparing them for the next git commit. It moves changes from the working directory into the index without committing them. By default, it stages entire files specified by pathspecs.

Use git add <file> for specific files, git add . for the current directory recursively, or git add -A to stage all changes repository-wide, including new files, modifications, and deletions.

Options enable selective staging: -u for updates (modified/deleted files only), -p for interactive hunk-by-hunk selection, and -N to mark files for future addition without staging content. It supports sparse-checkout and handles submodules.

Common workflow: edit files, run git add, then git commit. Always verify with git status or git diff --cached. Interactive modes (-i or -p) are powerful for partial commits.

CAVEATS

Does not commit changes—only stages them. -A stages everything; use cautiously in large repos. Ignores files in .gitignore by default unless -f. Submodule changes require separate handling.

COMMON EXAMPLES

git add file.txt
git add . (current dir)
git add -A (all changes)
git add -p (interactive)

VERIFICATION

Use git status or git diff --cached to review staged changes before commit.

HISTORY

Introduced in Git 1.0.0 (April 2005) by Linus Torvalds as core staging command. Evolved with interactive features in Git 1.5 (2007) and sparse-checkout support in Git 1.7 (2010). Remains fundamental in modern Git workflows.

SEE ALSO

git commit(1), git status(1), git diff(1), git rm(1), git stash(1)

Copied to clipboard