How to add all tracked files in Git

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


This guide will explain what it means for a file to be tracked, how to add tracked files, and cover various examples involving tracked and untracked files in Git.

In Git, a tracked file is any file that has been previously staged or committed to your repository history. Git monitors these files for changes. When you modify a tracked file, Git recognizes it as modified but not yet staged for the next commit. In order to stage the changes you've made you need to "add" them to the the staging area. This is the location Git uses as the state in-between your local directory, the code stored on your machine, and the remote repository, the code hosted on the server.

Untracked files, on the other hand, are those that are present in your directory but have never been added to your Git repository. These could be new files you've created that you haven't committed or staged yet. These files exist on your local machine, but Git has no knowledge of their contents or history.

To add all tracked files to the staging area in Git, you can use the following command:

Terminal
git add -u

The -u option tells Git to update the staging area with all changes made to tracked files (this includes modifications and deletions, but not new files). This is useful for preparing to commit changes made to files already known to your Git repository. This option will ensure Git does not affect any untracked files.

The only files that will be added are the tracked files that were modified. If there are tracked files that don't have any changes, they will be unaffected by the git add command.

To add both tracked modifications and all new untracked files, you can use:

Terminal
git add .

This command stages all changes (including new files, modified files, and deletions) in the current directory and its subdirectories.

Note that git add . stages new and modified files in the current directory and its subdirectories to the staging area, but it does not stage deleted files unless explicitly specified. In contrast, git add --all stages all changes including new, modified, and deleted files across the entire repository, not just the current directory.

For more specificity, especially in larger repositories where you only want to add modified files in a specific folder, use:

Terminal
git add -u <folder_path>

This adds only the modified tracked files in the specified folder, leaving the rest untouched.

To add only untracked files without adding any modifications to tracked files, you can use a combination of commands to filter out only the untracked files:

Terminal
git ls-files --others --exclude-standard | xargs git add

This sequence uses git ls-files to list all of the untracked files in your local directory, filtering them with --exclude-standard to avoid adding files ignored by .gitignore, then pipes them to git add via xargs.

You can also accomplish the same thing interactively using git add -i. Once in the interactive prompt, choose a which stands for "add untracked", then * to choose every file, then q to exit the operation.

To stage all changes in your working directory including new files, modified files, and deleted files, use:

Terminal
git add -A

or equivalently,

Terminal
git add --all

These commands are the most comprehensive for staging, as they indiscriminately add all changes to the staging area.

If you want to add all files with a specific extension within your project, use:

Terminal
git add *.<extension>

For example, to add all Python files:

Terminal
git add *.py

For further reading on adding files in Git, see the official documentation.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2