Ignoring Files
Last updated
Last updated
Certain projects may include private files (like secrets) or downloaded content (like dependencies). Such files may contain very sensitive information or very large amounts of data and they should not be included in ANY snapshots of the project.
This is where ignoring files with .gitignore
comes into play.
To start, let's create a new file secrets.txt
:
If you run git status
, you will notice that Git prompts you to stage secrets.txt
. But we don't want that to happen. So we can add a file .gitignore
and add the path to secrets.txt
:
Then, when you run git status
again, you will notice that Git no longer prompts you to stage secrets.txt
. Wonderful!
You can find a set of predefined .gitignore
files here: https://github.com/github/gitignore
We highly recommend going with them for any project so that you are not redefining/missing any common files and folders that should be ignored.
When creating a repository on Github, can select a predefined .gitignore
to be added in the repository so you can save a step of adding the file
Typically, we ignore files like build artifacts and generated files that are usually derived from the human-authored code in the repository.
Dependency caches like /node_modules
Compiled code like .o
, .pyc
files
Build output directories like /bin
, /out
Runtime-generated files like log files
Personal configuration files e.g. of your IDE