Don’t Ignore .gitignore
If you are a developer or have used git, you might have heard the term gitignore. So what is a .gitignore and why should you stop ignoring it.
What is a .gitignore?
A gitignore is a special file that specifies intentionally untracked files that Git should ignore. Sometimes there might be files in your project which you don’t want to commit to the version control for reasons like:
- The file might hold some secret information like your API key/secret, APP secrets, or some username/password, server config, etc.
- It might contain some configuration specific to your machine only and don’t want to commit to the version control
- It might be some installed dependencies like node_modules or bower_components
- It might be a machine specific useless file like .DS_store files
Gitignore is a great way to avoid unwanted files to be pushed to the server. But do I really need to learn now?
Dark Side of gitignore
What will happen if you ignore .gitignore
If you have come credentials or config file on your project you should take gitignore seriously. If you ignore the .gitignore you might leak your secret credentials yourself. If you search on Github for some config files you can find out the emails/passwords, API keys and APP secret key of many projects. If on wrong hands you might be in trouble since they can change the credentials or even use it for wrong this like sending spams and pushing updates with exploits.
For example searching filename .env with password https://github.com/search?q=filename%3A.env+password&type=Code will give you a bunch of credentials.
Author is not responsible for illegal use of the provided URL. The URL is provided for information use and awareness only
Now that we agree on not ignoring the gitignore,
How can we implement it
How to use gitignore
Using gitignore is as easy as creating a file and entering the file name you don’t want to push inside the file. You can also ignore files as well as folder. Also you can use pattern formats to ignore a bunch of files and folder at once. For example you can use *.c
to ignore all files with the file extension c. You can learn about the various patters you can use in gitignore here. If you are creating a project on github, gitlab etc you can choose the .gitignore file template according to the project framework or language you are going to use and it will generate a .gitignore file for you. Moreover you can gitignore generator like gitignore.io