As a git noob trying it out on a Rails project, I am wondering if it is bad practice to do git add . (add current directory) before every commit. The intro tutorials I have seen show adding the current directory initially, then using git add new_file to add files after that. If I’m adding a bunch of files from a bunch of different directories, this seems too hard.
Essentially, if you are adding more than one or two files, is it OK to use git add . every time I want to commit? Is using git add . the same as explicitly doing git add new_file for every file that has been created since the last commit?
git add .will add everything that’s in the heirarchy, including new files. If you want to track all files that are in the directory, this is fine.Another (perhaps more common) usage is to do
git commit -a, which adds only the files that changed since the last commit before committing, and doesn’t include any new files.EDIT:
git add .won’t remove any files that were deleted since the last commit. If you’re deleting files, I’d usegit rm <myfile>so that git is informed of the removed file, and you don’t forget to make sure git knows it was deleted. As mentioned in another comment,git commit -awill notice files that have been deleted.