It is probably better to not get in the habit of git add .
in the first place. If you are committing, you probably want to be aware of what you are committing rather than just assuming things are what you think they are.
If you do happen to commit things that should not be there though, you can amend your commit with git commit --amend
after doing a git reset unwanted_file_addition.txt
, for example.
If you have pushed a commit up that contains confidential information you will have some additional work to do.
See this recent GitHub Article released in October, if that has happened. It shows how to take care of that issue.
They also reflect my sentiments on the broader stroke ways of adding files: "If you're working from the command line, avoid the catch-all commands git add . and git commit -a, instead use git add filename and git rm filename to individually stage files."
Files that are used in general for your environment, such as editor swap files, project files, such as .project
and operating system files that may pollute your projects should be in your system or account .gitignore
file located in either /etc/ or other system wide location, and more specific to your personal tools, in your home folder.