Staging in Git (original) (raw)

Last Updated : 7 May, 2026

In git the staging area (also called the index) is an intermediate space where changes are gathered before they are committed. Think of it as a draft board: you can organize and review what changes you want to include in the next commit. The staging area allows you to:

Git Staging Workflow

Staging

Workflow

Basic Staging Commands

**1. Staging All Changes

To stage all modified files in your working directory, use:

git add .

Alternatively, you can use:

git add -A

This adds all changes, including new, modified, and deleted files.

2. Staging Changes in a File

Let’s say we edit a.txt and run:

git status

Example:

3. Unstage a File

To remove a file from the staging area, use:

git reset file_name

Example:

git reset b.txt

The file remains in your working directory but is removed from staging.

4. Staging Changes by Hunk

Sometimes you want to stage only parts of a file. Git allows hunk-level staging:

git add -p

This opens an interactive prompt for each hunk (block of changes) in the file:

Stages of Hunk Action Performed
y Stage this hunk for the next commit
n do not stage this hunk for the next commit
q quit; do not stage this hunk or any of the commits
a stage this hunk and all later hunks in the file
d do not stage this hunk or any of the later hunks in the file
e manually edit the current hunk
? print hunk help

This is useful when you want to commit only specific changes while leaving other changes unstaged.

5. Interactive Add

Git also provides an interactive staging interface:

git add -i

This interface breaks down the output into staged and unstaged changes. You can perform various actions:

Staging Specific Cases

1. Stage a Single File

git add file_name

**Example:

git add b.txt

2. Stage Deleted Files

git rm -f file_name

git rm --cached file_name

**Example:

git add r.txt