Difference between “Git Add -A” and “Git Add .”

Better Stack Team
Updated on June 24, 2024

The commands git add -A and git add . both add changes in the working directory to the staging area (index), but they differ in the scope of changes they consider.

git add -A

  • git add -A stages all changes, including modifications, deletions, and additions, in the entire working directory and all its subdirectories.
  • It's equivalent to git add --all and ensures that all changes, regardless of their location in the directory tree, are staged for the next commit.

git add .

  • git add . stages changes in the current directory and all its subdirectories, but it does not include deletions.
  • It stages modifications and new files, but it does not stage deletions or changes in files that have been removed.
  • It's a more conservative option compared to git add -A as it only stages modifications and new files within the current directory and its subdirectories.

Summary:

  • If you want to stage all changes, including modifications, deletions, and additions, across the entire working directory, use git add -A.
  • If you only want to stage modifications and new files within the current directory and its subdirectories, but not deletions, use git add ..

Additional Note:

  • Both commands add changes to the staging area, but they don't commit the changes. You still need to run git commit to commit the staged changes to the repository.
  • Be careful when using git add -A as it stages all changes, including potentially unwanted deletions. Always review the changes before committing.
  • Always use these commands with caution, especially when working on shared repositories, to ensure that you're only staging the changes you intend to include in the next commit.