git add is the first step in every Git commit workflow. This tutorial explains how staging works, how to add specific files or hunks, and how to avoid the common mistake of committing unwanted changes.
The Problem
You've made changes to several files but you only want to commit one of them. Or you ran `git commit` and nothing happened because you forgot to stage anything first. Sound familiar?
The staging area is what makes Git so precise. It lets you build exactly the commit you want — including partial changes within a single file — rather than blindly committing everything at once. Mastering `git add` is the first step to writing a clean, readable Git history.
Common mistakes developers make with this:
Running `git commit` without staging anything first
Using `git add .` and accidentally staging files you didn't intend to commit
Staging a file and then editing it again without re-staging
Confusing `git add` (staging) with saving a file in your editor
Gitoryx: In Gitoryx, staging is visual: you see every changed file in a panel and can check individual files — or even individual lines — into the staging area before committing.
What is Add: How to Stage Changes Before a Commit?
`git add` moves changes from your working directory into the staging area (also called the index). Only staged changes are included in your next commit. You can stage entire files, specific files, or even individual hunks within a file.
Step-by-Step Guide
1
Check what has changed
Before staging anything, get a clear picture of what's modified in your working directory.
bash
git status
# Output:
# Changes not staged for commit:
# modified: src/app.ts
# modified: src/utils.ts
# Untracked files:
# README.md
Red = not staged. Green = staged. Untracked files have never been added to Git before.
2
Stage a specific file
Pass the file path to `git add` to stage only that file. You can list multiple files separated by spaces.
bash
# Stage one file
git add src/app.ts
# Stage multiple files
git add src/app.ts src/utils.ts
# Stage all files in a directory
git add src/
3
Stage all changes at once
`git add .` stages every modified and untracked file in the current directory and below. Useful when you want to commit everything, but be careful — it picks up files you may not intend to track.
bash
git add .
# Verify what's now staged
git status
Always check your `.gitignore` before running `git add .` to make sure build artifacts, secrets, and node_modules aren't being staged.
4
Stage parts of a file (interactive / patch mode)
If you only want to commit some of the changes in a file, use the `-p` (patch) flag. Git will show you each changed hunk and ask: stage it (y), skip it (n), split it (s), or edit it manually (e).
What is the difference between `git add .` and `git add -A`?
`git add .` stages all changes in the current directory and subdirectories. `git add -A` stages all changes across the entire repository, including deletions and renames in any directory. In modern Git (2.x) the behavior is nearly identical when run from the repo root.
Can I stage only part of a file?
Yes. Use `git add -p` (patch mode) to interactively select which hunks within a file to stage. You can also use `git add -e` to edit the patch manually.
What happens if I edit a file after staging it?
The new edits are not automatically staged. Git tracks the file state at the time of `git add`. You need to run `git add` again to include the latest changes.
How do I unstage a file?
Use `git restore --staged <file>` (Git 2.23+) or `git reset HEAD <file>` on older versions. This removes the file from the staging area without discarding your changes.
Everything in this tutorial is faster and clearer with a visual Git client. Gitoryx is free, runs natively on macOS, Windows, and Linux, and built for developers who want to move fast without breaking things.