Have you ever wondered what’s 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):
- If you are in the project’s main working directory, git add . and git add -A do the exact same.
- If you’re working in a subdirectory of the project, git add -A adds all files in the entire working directory but git add . only adds the files in the subdirectory.
Let’s take a look at the differences between different options of the git add command. Besides, you’ll find a concrete example that supports understanding the difference 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:
|git add -A||git add –all||Stage all new, modified, and deleted files|
|git add .||–||Stage all new, modified, 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|
Let’s see a concrete example that demonstrates 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 working directory of the project. Then navigate to the examples folder and modify the example1.txt file.
In the examples folder, let’s do the git status command:
Because the Terminal window is opened in the subdirectory examples, the status shows that there’s a change 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 . command doesn’t stage the changes in the parent folders! This is why the file1.txt changes weren’t staged.
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:
Thanks for reading. Happy coding!
About the Author
- I'm an entrepreneur and a blogger from Finland. My goal is to make coding and tech easier for you with comprehensive guides and reviews.
- Artificial Intelligence2023.03.14Best AI Tools of 2023 (Save Time & Boost Productivity)