Skip to content

add Git Command Guide

The git add command is used to stage changes to the working directory for the next commit. Staging allows you to control what changes are included in each commit, providing flexibility in managing your Git projects. Options like —all and —patch enable selective staging of files and changes.

Terminal window
git add [options] <pathspec>
OptionDescription
-A, —allAdd all changes in the working tree
-p, —patchInteractively choose hunks to stage
-n, —dry-runDon’t actually add, just show what would be added
-f, —forceAllow adding otherwise ignored files
-u, —updateUpdate only tracked files
-i, —interactiveAdd interactively
—ignore-removalSkip deletions
—intent-to-addAdd without staging
ParameterDescription
pathspecFiles or directories to add

Stage all changes in the current directory

Section titled “Stage all changes in the current directory”
Terminal window
git add .

Stages all changes in the current directory and subdirectories.

Terminal window
git add file1.txt file2.md

Adds only the specified files to the staging area.

Terminal window
git add --patch

Allows you to review and stage individual hunks of changes.

Terminal window
git add -u

Stages modifications and deletions, but not new files.

Terminal window
git add --dry-run --all

Shows what files would be added without actually adding them.

How do I add all new and modified files in Git?

Section titled “How do I add all new and modified files in Git?”

To add all new and modified files to Git, use the following command:

Terminal window
git add --all

How can I interactively select changes to stage using git add?

Section titled “How can I interactively select changes to stage using git add?”

To interactively select changes to stage, you can use the patch option with git add:

Terminal window
git add --patch

How do I add only specific files to the staging area?

Section titled “How do I add only specific files to the staging area?”

To add only specific files to the staging area in Git, execute:

Terminal window
git add <filename>

How can I see what git add will do without actually adding?

Section titled “How can I see what git add will do without actually adding?”

To preview what git add will stage without making changes, use:

Terminal window
git add --dry-run

How do I stage deleted files using git add?

Section titled “How do I stage deleted files using git add?”

To stage deleted files in addition to modified ones, use:

Terminal window
git add -A

How can I ignore certain files when using git add?

Section titled “How can I ignore certain files when using git add?”

To ignore files that are typically ignored by .gitignore when using git add, ensure your .gitignore is correctly configured, and use git add as normal.

  1. Staging all changes for the next commit
  2. Adding specific files or directories to the staging area
  3. Selecting specific changes interactively for staging
  4. Updating the staging area with tracked file changes
  5. Adding files while ignoring removal operations
  6. Forcing addition of otherwise ignored files
  7. Previewing what would be staged without making changes