Key concepts

Staging area

In Git, the staging area (also known as the index) is an intermediate area where you can prepare and review changes before committing them to the repository. It acts as a buffer between your working directory and the repository, allowing you to selectively add and remove changes to be included in the next commit.

The staging area serves several purposes:

  1. Selective commits: You can choose which changes to include in the next commit by adding only the desired files or portions of files to the staging area. This allows you to create focused and meaningful commits that address specific tasks or features.

  2. Review changes: Before committing, you can review the changes in the staging area to ensure they are correct and complete. This helps catch any unintended modifications or additions before they become part of the repository's history.

  3. Incremental updates: The staging area enables you to stage changes incrementally. You can add changes to the staging area, continue working on other modifications, and then add more changes later. This flexibility allows you to build up a commit gradually over time.

  4. Separation of concerns: By using the staging area, you can separate the process of making changes in your working directory from the act of committing those changes to the repository. This separation provides a clear distinction between work in progress and completed work ready to be recorded in the repository's history.

Examples

View the status of the staging area and your workspace:

git status

Add a single file to the staging area:

git add myfile.txt

Add all changes in the directory to the staging area, including new files and modifications:

git add .

Commit the staged changes to your repository's history with a given message:

git commit -m "Add feature XYZ or fix bug ABC"

Remove all changes from the staging area (but don't undo the actual changes):

git restore --staged .

The . character above points to the current directory, meaning "all changes in the current directory," but you can also specify a particular file or directory:

git restore --staged path/to/file.txt
© 2024-2025 GitByBit.All rights reserved.

Hi! I'm Alex, creator of GitByBit.

And this is Gitopedia—a reference that summarizes knowledge in my Git course.

Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:

Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.

The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.

Learn Git in VS Code