Skip to main content

What is the git add command used for?

git add is used to add changes to the staging area (index), that is, to prepare files or parts of them for the next commit.

What git add does

After changing files:

text
Working directory → (git add) → Staging area → (git commit) → Repository

git add:

  • does not save changes permanently
  • does not create a commit
  • just marks changes that will go into the next commit

Main use cases

Add a single file

bash
git add index.js

Add all changes

bash
git add .

Adds:

  • new files
  • modified files
  • deleted files

Add part of a file (interactively)

bash
git add -p

Allows you to:

  • choose specific changes (hunks)
  • make logically clean commits

Add all files of a certain type

bash
git add "*.ts"

Frequent mistakes

  • Thinking that git add immediately makes a commit
  • Using git add . without checking git status
  • Adding .env, node_modules, build artifacts

Relation to git status

After git add:

bash
git status

Shows:

  • Changes to be committed
  • Changes not staged for commit

Short version for an interview

git add adds changes from the working directory to the staging area, preparing them for a commit.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.