AlgoMaster Logo

Adding Files to Staging Area (git add)

Last Updated: January 3, 2026

6 min read

Understanding how to properly use git add is crucial for developers looking to manage their source code effectively. This command is the gateway between your working directory and the staging area, where changes are prepared for commit.

The Role of git add

At its core, git add does one simple but powerful thing: it takes changes you’ve made in your working directory and prepares them for the next commit.

Git doesn’t commit your edits automatically. Instead, it uses the staging area to keep track of exactly which changes should go into the next snapshot.

When you run git add, you’re effectively telling Git:

“These are the changes I want to include in my next commit.”

Later, when you run git commit, Git takes whatever is staged and turns it into a permanent commit in your repository’s history.

Basic Usage

The most common usage of git add is very direct:

This command adds the specified file to the staging area. For example:

This stages the current version of app.js for the next commit.

You can also stage multiple files by listing them:

If you want to stage all modified and newly created files in the current directory and its subdirectories, you can use:

This is convenient, but it also means you should be careful, you might stage more than you intended if you’re not paying attention.

Working with Directories

You can also add entire directories using git add <directory_name>. For instance:

This stages all changes inside the src directory (and any of its subdirectories): new files, modified files, and deleted files. It’s a quick way to stage a whole part of your project when you know all the changes in that folder belong together in a single commit.

Best Practices for Using git add

As you become more comfortable with git add, consider these best practices to maintain a clean and manageable commit history.

When using git add, aim to stage changes that are related to the same logical task. For instance, if you're fixing a bug, stage all changes related to that bug fix together. This makes your commit history clearer and more meaningful.

Use .gitignore Wisely

Ensure you have a proper .gitignore file in place. This file tells Git which files or directories to ignore, preventing them from being accidentally staged.

Typical examples include:

  • Build artifacts
  • Logs
  • Dependency directories

Stage with Intent

Instead of running git add . mindlessly, take the time to review changes with git status and git diff. This ensures you’re only staging what you truly want to commit, reducing the likelihood of including unwanted changes.

Now that you understand how to use git add to prepare your changes for commit, you're ready to explore the next step in the Git workflow—committing those changes.

In the next chapter, we will look at how to finalize your modifications and share them with your team, ensuring your commits tell a coherent story.