"Dear Jacob" Git advice: git add -u
I recently received a request that I start a "Dear Jacob" advice column for git, and thought that it was a pretty nifty idea. I needed a good excuse to post more frequently, and I do end up answering a lot of questions about Git for the people that I know.
Welcome to the first installment of the "Dear Jacob" Git advice column!
The first tip comes about because of wanting to add all of the modified files to the index, without adding any test, or experimental files that might also be in your tree.
My first thought would be to try
git add -a. Unfortunately, that
doesn't work at all (even though
-a is what you'd want if you were
doing git commit in this case). With git add,
you actually want
Anyway, the disjunction resulted in the person doing
git diff --name-only | xargs git add whenever they wanted to add only
the modified files in their repo. They couldn't use
git add . to add
everything, since they potentially had some test/experiment files that
they didn't want to track.