What is Gitignore? Is it important?

As devs, we all know Git to manage source code. And sometimes when working in a team you often encounter cases where two guys or the whole team are constantly struggling because of junk files such as compiled files, log, config, and the banks are. And so Gitignore was born to solve that problem.


What is Gitignore?

Gitignore is a file called .gitignore by Git guy, its task is to list the files that you don't want to put in git or it is dangerous that Git will ignore those files.

How it works

When adding a new file to git, git will check the list of guys who will ignore it in the .gitignore file and ignore them. Well that is only a necessary condition, it is sufficient that it is not in git cache anymore, it will be ignored by git if it is in git cache, then .gitignore will be useless.

Common pattern formats

  • Use # to comment and can leave the line way for easy reading.
  • The simplest is the file name to ignore: example.exe
  • Or the whole directory: example_folder /
  • When ignore the directory , there should be a / after the directory name to identify it as a directory, otherwise it can be considered a directory or file or symbolic link.
  • Sign! The front has a negative meaning:! abc / example.exe
  • Use 1 * to find files of the same format. For example, if you want to ignore all .xml files in the project: * .xml
  • Another case of 1 * if you specify the example path: config / *. Xml, it is only valid for config / abc.xml files that are not valid for config / sub / abc.xml files.
  • Use ** to take effect for folders that do not need to specify a name. For example: ** / foo will be valid for all files or directories named foo everywhere in the project.
  • Or use the / ** folder type to be valid for all files inside the folder.


Well, the technology is modern, so we don't have to struggle with our hands anymore, but most IDEs support it , if not, you can install additional plugins or configs somewhere. I can choose the type of project I am working on and it will automatically generate the corresponding .gitignore file.

Or simply go to gitignore.io then select the type of project you are working on. For example, I am using WebStorm (of Jetbrains) and Node.js code:


It will then create a delicious .gitignore file for you. For example, a Node.js project will look like this:

Coverage range

The .gitignore file will affect files and directories with it or its descendants. Usually the project only needs one external .gitignore file to be enough, but if the project is too large, we can split the .gitignore file into each small folder for easy management.

When to use Gitignore?

Any project should use it, you should create the .gitignore file in the root directory immediately after initializing your project and listing the files that you want to ignore (ignore). Why should I list first? Read the bottom will be clear?

Life is not a dream

Suppose this is! You just joined the project and saw the project during the conflict because of some junk files but luckily you read this article and you are very smart, so create the .gitignore file for the project and add that junk file to the .gitignore and you Delete junk files and commit. So what! Another guy pulls the new code back to create that junk file and it still sticks to normal git. Porking? “ You put it in .gitignore already? .


Why? Because that file has been collected by the git cache guy into its disciples, it is still possible for the git to manage the file. So the simple way to solve it is to free the file from git cache , complete with a divine command :

Since that file is no longer a git cache topic, it is not under git's management and now .gitignore works. The reason is that, but if you need to reset all the projects for .gitignore to work properly then I usually delete all the files of git cache too ?

Then I will add all the files to the project as I created the project.

And now you commit and push as normal in the district.


Well, this song has nothing to conclude :)) Can you try it on your project and see if it is important or not?

ITZone via blogk.xyz

Share the news now