Configuration controls which files in the working directory should not be stored in version control.This is called “gitignore” or “excludesfile.”
Some files don’t belong in version control. Maybe they’re big binaries that can be derived from the source already stored. Maybe they’re IDE configuration files that are specific to your local environment.
Github has good examples of gitignore files for various kinds of projects. TODO: link
Ignore files that are personally yours. IDE configuration is an example. Personally, I name all my temp files “carrot.”
Ignore temporary files created by editors or operating systems. This will depend on your editor.
Ignore files that are generated in the build.
Like most git configuration, you can tell it to ignore certain files either locally or globally. Either way, the technique is to create a file that holds the names of all files that shouldn’t be stored in the repository. Here, “names” include wildcards, paths, etc. TODO: link to some external documentation with details
What should be ignored locally? Anything that should be ignored by all users of this project. If everyone uses the same IDE, put IDE configuration files here. Files created by this project’s build should be ignored at this level, too.
This is easy. Put the list of stuff to ignore in
.gitignore in project root.
This will ignore files in every repository you (as your user) use. I like to use this for my editor’s temp files and irritating files my OS likes to create. Since global ignores are user-specific, these are files specific to me and my environment.
No, .gitignore should be commited to the repository. All copies of this repository should be ignoring roughly the same files. Otherwise, those files you want to ignore will be committed by someone else, and confusion ensues.
If there are some files you want to ignore but someone else might not, then put them in your global excludes; those are personal to you. Remember that the goal is to avoid surprise.
If you commit files and later decide to ignore them, you have to delete them from the repository. Git can’t just forget about files it knows and loves.
git rm -f <file or directory you want to ignore>
git rm says “Officially delete this file from the repository.” For ignored files, this deletion is separate from whether the file still exists in your current directory. (todo: show git status) Comitting this will make the file untracked. Ideally, do this in the same commit as updating .gitignore.
git commit -m "Deleting files that should be ignored"