Ignoring Files in Git

Posted on August 04, 2018


In every repo, there are some files that you don't want to commit. These are files that contain secret credentials, API keys, or files specific to the your local computer like logs, configs or installed packages. For example, a JavaScript project always has a node_modules directory, in which the dependencies of the project is being installed. This is a problem because it will cause Git to track dependencies, which can amount to Gigabytes of space, slowing down operations such as switching branches. You don't need to track someone else code.

The solution offered by Git is to use a special configuration file named .gitignore. You can put one in your project and list the name of files you want to ignore there.

$ echo "node_modules" > .gitignore

Now git status will show .gitignore as untracked. Add and commit in into your repo. Now you're good.

Share this:
LinkedIn
Reddit
WhatsApp

Get Free Guides