Ignoring Files in Git

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.

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.