Skip to content

Instantly share code, notes, and snippets.

@dsernst
Last active January 25, 2024 17:00
Show Gist options
  • Star 64 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save dsernst/ee240ae8cac2c98e7d5d to your computer and use it in GitHub Desktop.
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.

@aperkaz
Copy link

aperkaz commented Jan 3, 2018

Thanks for the quick clarification, very helpful 🙂

@ameenaziz
Copy link

good explanation 👍

@codesrepo
Copy link

thank you! simple and to the point explanation!

@jbarcas
Copy link

jbarcas commented Sep 28, 2018

nice!

@ionutblt
Copy link

ionutblt commented Oct 3, 2018

tx

@MingleiLI
Copy link

thanks

@chensiyuan0214
Copy link

Thanks very much for this explanation

@alwaifqp
Copy link

alwaifqp commented Dec 6, 2018

help a lot

@MGhandour92
Copy link

Thank you :)

@merciof
Copy link

merciof commented Jan 5, 2019

Thank you!

@sehmbimanvir
Copy link

Thank You 👍

@IvenBach
Copy link

IvenBach commented Feb 1, 2019

👍

@joelamajors
Copy link

Thanks!

@andreiverdes
Copy link

👍

@ShileiMao
Copy link

thanks for the explanations

@NathanSweet
Copy link

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

@mathmmo
Copy link

mathmmo commented Mar 14, 2019

Thanks!

@maurisrx
Copy link

maurisrx commented Mar 20, 2019

Thanks! 👍

@dsernst
Copy link
Author

dsernst commented Mar 27, 2019

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

Can you describe an example to clarify?

@oluTV
Copy link

oluTV commented Apr 7, 2019

thanks

@imfromthenet
Copy link

Thank you, this is a very good explanation!

@BenjaminGHo
Copy link

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

thanks so much!

@dawei0716
Copy link

ty

@leandwo
Copy link

leandwo commented May 13, 2020

thx

@Ravin001
Copy link

thanks

@BraveTea
Copy link

Thank you for the explanation!

@Gabrielarsluz
Copy link

Obrigada, Thank you :)

@ahmederrami
Copy link

Thanks

@zothsu
Copy link

zothsu commented Jan 25, 2024

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

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