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

Assuming a .gitignore which contains the following –


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.

Also, build/ ignores that folder anywhere.

a fully qualified path name is required if the file / folder is to be ignored specifically at a location.

So, /index.html ignores the index.html file only in the root folder

And, /foo/bar/baz/ 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!

Adding, to the .gitignore will not ignore the file if it is already part of the repository.