Have you ever wondered the difference between the commands git add . and git add -A?

The detailed answer depends on the Git version you’re using. In Git 2.x (which you are likely using):

  • Use the command git add . If you are in the project’s main working directory. similarly, as does git add -A
  • Use git add -A if you’re working in a project subdirectory, adds all files in the entire working directory but git add. Only adds the files in the subdirectory.

Let’s look at the differences between different options of the git to add command. Additionally, a real-world example is provided to help you grasp the distinction between git add. and git add -A.

Different Options with ‘git add’ Compared

Here’s a table that summarizes the differences between git add . and git add -A as well as some other git add options:

Command Shorthand for Description

git add –a

git add –all
Stage all new, modified, and deleted files

git add .

----

Stage all newmodified, and deleted files in the current folder

git add –ignore-removal .

---

Stage new and modified files only

git add -u

git add –update

Stage modified and deleted files only

Demonstrative Example

Let’s see a concrete example demonstrating the clear difference between git add . and git add -A.
I have a sample Git project with the following structure:

				
					/DemoProject
  .git/
  examples/
    example1.txt
  file1.txt
				
			

Now, let’s change the file1.txt in the project’s working directory. Then navigate to the examples folder and modify the example1.txt file.

In the examples folder, let’s do the git status command:

gitt add

Because the Terminal window is opened in the subdirectory examples, the status changes in the parent folder ../file1.txt and example1.txt.

Now, let’s see what happens when we run git add .

				
					$ git add .
				
			

As a result, the changes in the current directory are staged for a commit. But as you learned, the git add . The Command doesn’t stage the changes in the parent folders! This is why the file1.txt changes weren’t staged

gitt add

To stage all changes in the current directory as well as the parent directory, you can use git add -A.

				
					$ git add -A
				
			


Now both locations’ changes are staged for commit:

gitt add


Thanks for reading. Happy coding!