Back
GitoryxGitoryx
Beginner7 min read

Git Add: How to Stage Changes Before a Commit

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).

bash
git add -p src/app.ts

# Git shows each hunk:
# @@ -10,6 +10,7 @@
# -  const old = true;
# +  const updated = true;
# Stage this hunk? [y,n,s,e,?]

Patch mode is the key to writing atomic commits — one logical change per commit.

See this workflow in Gitoryx — Gitoryx screenshot

See this workflow in Gitoryx. See all changed files color-coded in the commit panel

Free download
5

Review what is staged before committing

Use `git diff --staged` (or `--cached`) to see the exact diff of everything that will go into your next commit.

bash
git diff --staged
6

Unstage a file if you change your mind

If you staged something by mistake, you can remove it from the staging area without losing your changes.

bash
# Modern Git (2.23+)
git restore --staged src/utils.ts

# Older Git
git reset HEAD src/utils.ts

Common Mistakes to Avoid

Staging everything with `git add .` without reviewing

This often results in committing debug code, editor config files, or environment variables.

Fix: Run `git status` and `git diff` first. Use `git add -p` for fine-grained control.

Editing a file after staging it

Git records the state of the file at the moment you run `git add`. Any edits after that are not staged.

Fix: Re-run `git add <file>` after every edit, or use `git diff --staged` to confirm what's actually staged.

Not adding new (untracked) files

`git add .` is needed for new files that Git has never seen before — they won't be staged by other means.

Fix: Check `git status` for the 'Untracked files' section and add them explicitly.

Gitoryx — visual Git client for macOS, Windows & Linux
GitoryxGitoryx — macOS, Windows & Linux

Stage files and hunks visually in Gitoryx

  • See all changed files color-coded in the commit panel
  • Click to stage or unstage individual files in one click
  • Use the inline diff viewer to stage specific lines without touching the CLI
  • Gitoryx prevents accidental staging of ignored files
Download Gitoryx — FreemacOS · Windows · Linux · No subscription

Frequently Asked Questions

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.

See it in action with Gitoryx

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.