Git & GitHub Course
Git & GitHub
/
Beginner

git add

Definition

Adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.

Explain Like I'm New

This command places files into the 'waiting room' (Staging Area). You can add files one by one, or add everything in the folder all at once.

Real World Example

You fixed a bug in `app.js`. You type `git add app.js` to prepare it to be saved.

Common Use Cases

  • •Selecting specific files to commit
  • •Tracking new files

Crucial Command Flags

Flag / OptionDescription
-A / --allAdd all new, modified, and deleted files to the staging area.
.Add all new and modified files in the current directory.
-pPatch mode. Interactively choose chunks of files to add.

Terminal Output

bash / terminal
# Add a single specific file $ git add index.html # Add two specific files $ git add style.css script.js # Add an entire folder $ git add src/ # THE NUCLEAR OPTION: Add EVERYTHING in the current directory and below $ git add . # Add all files across the entire repository, regardless of current directory $ git add -A

Interview Questions

basic

  • How do you stage EVERY modified and untracked file in your current directory at once?

intermediate

  • What is `git add -p`?

Flash Cards

Question

Stage everything?

Click to reveal answer
Answer

`git add .` (The period means 'current directory and everything inside it').

Question

git add -p?

Click to reveal answer
Answer

The `-p` stands for 'patch'. It is a powerful feature that allows you to review your changes block by block, and stage specific lines of code within a file, rather than staging the entire file.