Skip to content

Instantly share code, notes, and snippets.

@dsernst
Last active January 29, 2025 15:16
Show Gist options
  • Select an option

  • Save dsernst/ee240ae8cac2c98e7d5d to your computer and use it in GitHub Desktop.

Select an option

Save dsernst/ee240ae8cac2c98e7d5d to your computer and use it in GitHub Desktop.
Compare `git add .` vs `git add -A`

git add . vs git add -A

Both of these will stage all files, including new files (which git commit -a misses) and deleted files.

The difference is that git add -A also stages files in higher directories that still belong to the same git repository. Here's an example:

/my-repo
  .git/
  subfolder/
    nestedfile.txt
  rootfile.txt

If your current working directory is /my-repo, and that's the root of this git repo (thus the .git/ folder), these two commands will do the same thing.

But if you rm rootfile.txt, then cd subfolder, git add . will not stage the change that ../rootfile.txt has been deleted, because git add . only affects the current directory and subdirectories. git add -A, on the other hand, will stage this change.

@MGhandour92
Copy link
Copy Markdown

Thank you :)

@duzitug
Copy link
Copy Markdown

duzitug commented Jan 5, 2019

Thank you!

@sehmbimanvir
Copy link
Copy Markdown

Thank You 👍

@IvenBach
Copy link
Copy Markdown

IvenBach commented Feb 1, 2019

👍

@joelamajors
Copy link
Copy Markdown

Thanks!

@andreiverdes
Copy link
Copy Markdown

👍

@ShileiMao
Copy link
Copy Markdown

thanks for the explanations

@NathanSweet
Copy link
Copy Markdown

Seems your example isn't great: git add . doesn't stage deletions, git add -A does.

@mathmmo
Copy link
Copy Markdown

mathmmo commented Mar 14, 2019

Thanks!

@maurisrx
Copy link
Copy Markdown

maurisrx commented Mar 20, 2019

Thanks! 👍

@dsernst
Copy link
Copy Markdown
Author

dsernst commented Mar 27, 2019

@NathanSweet: I believe git add . does stage deletions.

Can you describe an example to clarify?

@oluTV
Copy link
Copy Markdown

oluTV commented Apr 7, 2019

thanks

@imfromthenet
Copy link
Copy Markdown

Thank you, this is a very good explanation!

@BenjaminGHo
Copy link
Copy Markdown

Thanks for the great explanation! I just ran into this issue yesterday and didn't know why my upper level files were not being added.

@RosyMapleMoth
Copy link
Copy Markdown

thanks so much!

@dawei0716
Copy link
Copy Markdown

ty

@leandwo
Copy link
Copy Markdown

leandwo commented May 13, 2020

thx

@Ravin001
Copy link
Copy Markdown

thanks

@BraveTea
Copy link
Copy Markdown

Thank you for the explanation!

@Gabrielarsluz
Copy link
Copy Markdown

Obrigada, Thank you :)

@ahmederrami
Copy link
Copy Markdown

Thanks

@zothsu
Copy link
Copy Markdown

zothsu commented Jan 25, 2024

This gist is still great years later :) Thank you!

@renan-alm
Copy link
Copy Markdown

Yep, thanks for the straightforward explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment