Back
GitoryxGitoryx

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.

Beginner7 min readUpdated

On this page

What is git add?

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.

The short version

  1. 1Run git status to see what has changed
  2. 2Stage a file: git add <file>
  3. 3Stage all changes: git add .
  4. 4Stage partial changes: git add -p <file>
  5. 5Review staged changes: git diff --staged
  6. 6Commit: git commit -m 'your message'

Why it matters

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.

Where it usually goes wrong

  • 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

Git add, step by step

  1. Step 1: Check what has changed

    Before staging anything, get a clear picture of what's modified in your working directory.

    Terminal
    git status# Output:# Changes not staged for commit:#   modified:   src/app.ts#   modified:   src/utils.ts# Untracked files:#   README.md

    Tip: Red = not staged. Green = staged. Untracked files have never been added to Git before.

  2. Step 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.

    Terminal
    # Stage one filegit add src/app.ts# Stage multiple filesgit add src/app.ts src/utils.ts# Stage all files in a directorygit add src/
  3. Step 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.

    Terminal
    git add .# Verify what's now stagedgit status

    Careful: Always check your .gitignore before running git add . to make sure build artifacts, secrets, and node_modules aren't being staged.

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

    Terminal
    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,?]

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

    Git Add: How to Stage Changes Before a Commit: the same workflow in Gitoryx
    In Gitoryx: See all changed files color-coded in the commit panelHow it works
  5. Step 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.

    Terminal
    git diff --staged
  6. Step 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.

    Terminal
    # Modern Git (2.23+)git restore --staged src/utils.ts# Older Gitgit reset HEAD src/utils.ts

Mistakes to avoid with git add

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, since they won't be staged by other means.
Fix: Check git status for the 'Untracked files' section and add them explicitly.

Git add in 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.

  • 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

Free plan · no account required · macOS, Windows and Linux

Git add: 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.
All Git tutorials →
Gitoryx

Stop fighting Git. Start shipping.

Download the fast, native Git client that developers actually enjoy using.

v1.1.0 · macOS 12+ (Apple Silicon or Intel) · Windows 10+ · Linux x86_64