🌱 BasicsCommonly used

How to stage files in Git

Add files to the staging area before committing.

Stage a specific file
git add filename.txt

Stages a single file for the next commit.

When to use: When you want to commit only specific files.

Stage all changes
git add .

Stages all modified and new files in the current directory.

When to use: When you want to commit everything at once.

Stage all changes (including deletions)
git add -A

Stages all changes including deleted files. More thorough than git add .

Stage parts of a file interactively
git add -p filename.txt

Interactively choose which parts (hunks) of a file to stage. Press y to stage a hunk, n to skip.

When to use: When you want to split changes in one file into multiple commits.

← Back to Git Reference