Menu
Coddy logo textTech

Git Add

Last updated

git add moves changes into the staging area (the index), marking them to be included in your next commit. You can stage a single file, everything at once with git add ., or pick individual chunks interactively with -p. Staging is the step between editing files and committing them.

Try these in the terminal playground - a real shell in your browser, nothing to install.

git add copies changes from the working tree into the staging area - nothing is committed yet.

Syntax

CommandWhat it does
git add file.txtStage one file
git add .Stage all changes in the current folder
git add -AStage all changes in the whole repo
git add -pStage selected chunks interactively
git add *.jsStage files matching a pattern
git restore --staged file.txtUnstage a file (keep changes)

Common cases

GoalCommand
Stage everythinggit add .
Stage part of a filegit add -p
Unstage a filegit restore --staged file.txt
See what's stagedgit status

Git add FAQ

What does git add do?
It stages changes - copying them into the index so they'll be part of your next commit. Editing a file doesn't stage it; you run git add <file> to mark it ready. Then git commit records exactly what's staged. Staging lets you commit some changes while leaving others for later.
What's the difference between git add . and git add -A?
git add . stages changes in the current directory and below, including new, modified, and deleted files. git add -A stages changes across the entire repository regardless of your current directory. In a repo's root the two behave the same; they differ when you're in a subfolder.
How do I stage only part of a file?
Use git add -p (patch mode). Git walks you through each change ("hunk") and asks whether to stage it, so you can split unrelated edits in one file into separate commits. Press y to stage a hunk, n to skip it, s to split it further.
How do I unstage a file?
Run git restore --staged <file> (modern Git) or git reset <file> (older). Both remove the file from the staging area while keeping your edits in the working tree - the opposite of git add.
Can I practice this online?
Yes. Open the terminal playground to run git add in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers staging and committing step by step.
Coddy programming languages illustration

Learn Git with Coddy

GET STARTED