My main question here is whether iti makes sense to just always do git commit -am
instead of git add
. followed by git commit -m
?
I understand that -am indicates that it will add all changes from modified TRACKED files. So in a situation where I did not add any new files, it would make sense to just run git commit -am instead of git add, but would it be considered best practice to just do:
git add
.
git commit -am "message"
anyway?
or even instead:
git add -A
git commit -am "message"
would it be considered best practice to just do:
git add .
git commit -am "message"
anyway?
No, there is no such "best practice". As long as you do not want to include any untracked files, git add
+ git commit -m
and git commit -am
will do exactly the same.
There are two situations where you need to to use git add
:
The second point in particular is the reason many people recommend against always using commit -a
:
After working on code for a while, you often have several different types of changes in your working copy (the bugfix you were working on, some unrelated renaming, some temporary changes for debugging...). commit -a
risks putting too much into one commit - in these cases selective use of git add
is better.
But if you are certain you want to commit everything you changed, go ahead and use git commit -a
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With