Files and folders can be ignored in git using the .gitignore file. This means they are never added to the staging area or repository.
.gitignore is a plain text file that lists the files and folders to be ignored, on per line. Folders end with a forward slash and wildcards are available with the asterisk. Comments begin with the octothorpe.
A sample .gitignore file:
# Ignore the build directory and all files / folders in it
build/
# ignore all so files
*.so
# ignore the .directory file
.directory
We can ignore a previously committed file by removing it from the repository and adding it to the .gitignore. We can create .gitignore files here.