all you need to know about .gitignore
Tags: git, github, tutorial, beginners
Published: 2021-12-21 17:24:18

Hi everyone I am back with a new a new article of this series. Today I going to explain about `.gitignore` file and why to use , when to use are how to use. 

##why & when to use `.gitignore`?

In my previous article I have explained that git is a tracking software which tracks every single change on a particular repository, but in some cases we don't want `git` to track any changes to some file or folders in a `git` repository, and for this we use a `.gitignore` file.  Now let's understand this with an example, suppose you are building an application and in the same git repository you have created a Todo file where you written some tasks and you don't `git` to tack anything related to this file, or you don't want to commit this file to your codebase hosted at any of the popular providers like GitHub, GitLab, or Bitbucket, so in this case you can use a `.gitignore` file and add the file path to it , and then git will totally ignore this file or any changes made to it.

##how to create and use a `.gitignore` file 
After you are initialized a `git`  repository , simply open your code editor and create a new file and name it to `.gitignore` or if you are using git bash , navigate to your repository folder and then type `touch .gitignore` and this will also create a `.gitignore` file to your repository.
![create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gaw9al6jok2t6iklykff.png)
 


## how to add a particular file or folder to `.gitignore 

###`using git bash `
navigate to your repository in gitbash 

`git rm --cached <file>...
`
(This command will only work after you have added all files )
![ignore demo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1q570ni4kmaecnzx374.png)
see now we don't have the todo file in the commit area
![commit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iikqftl94rnsh22um6pn.png)
For adding a folder for ignoring
![folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzkrztpyejmefz426dxf.png)
see ab flolder is removed from the staging area 
 

You can also generate `.gitignore` templates form 
[.gitignore repo
 ]( https://github.com/github/gitignore)

or 
visit (https://www.toptal.com/developers/gitignore)[gitignore.io] 
to generate a predefined template for your project

##using editor
use `#` for comments 
`*.extntion ` to ignore all the files with this extension like `.txt` will ignore all the `.txt` files   
use `/` for directories like in this case if I add `ab/`to `.gitignore ` this will ignore everything in ab directory 

suppose you have ignored all th files with a particluar extension but now you want to commit a file with that extention in that case you can use `!` to neglect ignoring that file like `!hello.txt` this will neglect ignoring the hello.txt file 

![.ignore2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4hjt10krhqaf3n5ip36.png)

 
 ##Conclusion 
Now we are done with all you need to know about `.gitignore `. Feel free to comment out if you want to ask me something, and make sure to hit a  ❤️ if you love this article. Stay tuned for next one, Happy Coding :)

##Connect
 <a href="https://linktr.ee/kumarkalyan">
  <img align="left" width="100px" src="https://cdn.jsdelivr.net/npm/simple-icons@v3/icons/twitter.svg" />
</a>