Git

How to Git Add All Files Modified, Deleted, and Untracked?

Developers deal with multiple files while working on Git development projects. They need to create different files for each feature. Sometimes, it is required to modify the existing file or delete the old file that is not in use anymore. So, when new files are created, updated, or deleted in the project, it is also necessary to clear them from Git status by adding those files to the Git staging area.

How to Git Add All Files Modified, Deleted, and Untracked?

To Git Add all modified, deleted, and untracked files, different commands can be used, such as:

Method 1: Add All Files Modified, Deleted, and Untracked Using the “git add -A” Command

To add all the modified, deleted, and new untracked files to the Git staging area, execute the “git add -A” command in the working repository. For a practical demonstration, check out the following section.

Step 1: Navigate to Local Repository

First, execute the below-listed command and redirect to the desired directory:

$ cd "C:\Git\ReposC"

Step 2: Check Git Status

Then, display the current status of the working branch with the help of the given-provided command:

$ git status

It can be observed that currently there is one modified file, one deleted file and another one is an untracked file:

Step 3: Add Files

in order to add all those files to Git Index, execute the “git add” command along with the “-A” option:

$ git add -A

Here, the “-A” option is used to stage all files:

Step 4: Verify Changes

Lastly, check the Git status again to verify the new changes:

$ git status

According to the given output, all the files including modified, deleted, and untracked (new) files have been added to the Git staging area:

Note: If the deleted and new file is empty or the modification is not too severe, then the “git add -A” command will rename the new file with the deleted file. Moreover, the Git status will show that the “new file” is replaced with a “renamed” file.

Method 2: Add All Files Modified, Deleted, and Untracked Using the “git add .” Command

Sometimes, users want to add all the untracked, deleted, and modified files of the current working directory only. For this purpose, the “git add .” command can be utilized.

Step 1: View Current Status

First, check the Git status of the working directory:

$ git status

In the below-provided screenshot, the Git status displays the untracked, deleted, and modified files:

Step 2: Add Files to Git Index

Then, write out the “git status” command with the “.” symbol to add files to the Git index:

$ git add .

In the above-mentioned command, the “.” symbol is used to add only the current directory files:

Step 3: Verify Changes

Finally, view added changes by checking the repository’s status:

$ git status

It can be seen that all the files have been added to the Git index:

We have described the methods for adding all the files including the deleted, untracked, and modified files.

Conclusion

To add all the files, including modified, deleted, and untracked files, first, navigate to the desired repository and check its current status. Then, execute the “git add -A” or “git add .” command. This article has explained the methods to Git to add all files modified, untracked, and deleted.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.