What is the purpose of initializing a GitHub repository with .gitignore?

131 Views Asked by At

while I was creating a new repository on Github, I came across this option and I don't know what it is used for. The option is "Git ignore".Git ignore option

I clicked the button and many options popped up, chose "None".

the menu containing the different options

Any help is appreciated

1

There are 1 best solutions below

0
Vincent A. Cicirello On

A .gitignore file is a special file that you can include within a git repository that specifies what files and directories to exclude from the git. For example, you typically want to include source code files in the git repository, but not the result of compilation. So in Java, for example, you'd want to exclude .class files, which you can do within the .gitignore file.

The option that you discovered while creating a repository on GitHub is to initialize your new repository with a .gitignore file. The list of options that is in the screenshot you included is if you want to initialize a .gitignore with the commonly ignored files for a given language, rather than creating it yourself. It is a very handy feature since the default .gitignore files it creates are comprehensive of all of the various type of files you wouldn't likely want to include within the git repository itself for your chosen language.