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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github