To get git to exclude files and directories, we need to add a
.gitignore file in the root folder of the project.
Some of the things I learned from setting up my
.gitignore which contains the following –
.DS_Store build/ /index.html /foo/bar/baz/READTHIS.md
a file name or directory matches regardless of where it is.
So, in the example above it will ignore the
.DS_Store file regardless of whether it is in the root folder or somewhere deep inside.
build/ ignores that folder anywhere.
a fully qualified path name is required if the file / folder is to be ignored specifically at a location.
/index.html ignores the index.html file only in the root folder
/foo/bar/baz/READTHIS.md ignores that file only if it is present under
/foo/bar/baz and doesn’t ignore it anywhere else.
all this works only if the file / folder is not already checked in!
README.md to the
.gitignore will not ignore the file if it is already part of the repository.