gitignore file – How to add gitignore file to repo

In this article, we discuss the gitignore file in your GitHub repo. Also, how you can create the gitignore file and which file and folder you should include in your gitignore file.


gitignore file


What is gitignore file?

The purpose of a .gitignore file is to tell GitHub which files or folders to ignore when committing/tracking changes to a project. This can be useful for excluding files that are generated by the build process, temporary files, or files that are specific to a particular environment like config files. By ignoring these files, you can keep them out of your Git repository and keep your repo tidy.

How to add gitignore to the repo

To create a .gitignore file in the GitHub repo, create a new text file in the root folder of your repository with the name .gitignore and then add patterns for the files that you want to ignore. You can also use the below git commands to add gitignore to the repo-

git add .gitignore

git commit -m "Add .gitignore file"

gitignore file

To ignore files to commit add patterns for the files that you want to ignore. Each pattern should be on a separate line, and you can use wildcards to specify patterns for multiple files. Like the below pattern ignores the .log and bin directory in the next commit.



Once you have added the patterns then you will need to commit the file to your repository. You can do this by adding the .gitignore file to your staging area using the git add command and then committing it using git commit.

List of Gitignore files in the .Net project

There are a few common types of files in your .Net project that you might want to include in your .gitignore file-

Binaries files 

You can include patterns for files ending in .dll, .exe, or other binary file extensions to exclude them from your repository.



Debug symbols

If you are using a debugger to develop your .NET code, you may have symbols files like .pdb that are generated as part of the build process these can be excluded from your repository using a pattern like this:




Build output

The output of your build process like the bin folder that has to debug and release folder can be excluded from your repository using a pattern like this:


NuGet packages

If your project is using NuGet to manage dependencies then you will probably want to exclude the packages directory from your repository. This can be done using the below pattern –




You these all types of files you can exclude in your future commit by adding the same in your .gitignore file. Also, keep in mind that are some specific project files that you can add to exclude depending on your project need.


This is how you can create a .gitignore file and add it to your repo to exclude file types in your future commits.

Posted in git