git add

Jul 25, 2018 · 171 words · 1 minute read gittricks

How do you add files to your git repository? git add of course! Usually I add files using git add ., or git add path/to/files if the files I want to add are localized to a single directory but today I learned a new trick to add all changes to untracked files to your git repository.

I wanted to check in changes to existing files before I added new files to the repository. If I had only a few files I probably would have just staged them one at a time but I had several files. Additional these files were mixed in the same directory - so I couldn’t just add the directory. So I did what all programmers do: I searched Google and clicked on the first StackOverflow post.

It turns out you can use the -u option (short for --update) to stage changes to existing files (including deletions!) without staging new files.

I’m not sure how often I’ll use it, but I think this is a pretty neat trick.