Now a days, for developer Version Controlling is very important to maintain their codes. So, there are some files which developer doesn't want to push in the the git repository so to avoid this case there is ignore file feature in Git.

We just need to create a file named as '.gitignore' and put the file path of that file which we want to ignore. I am sharing some steps and commands which I use in my daily life.

Step 1: In your project root directory or where git is initialized, you need to create a file name as '.gitignore'.
Step 2: Now add the files you want to ignore.
Done! Git will not track that files.

Note: If file is already tracked then you have to do the following steps more. Let say 'example1.txt' file is tracked. Then you have to remove it from git first.
Step 1: git rm --cached example1.txt
Step 2: git add .
Step 3:
git commit -m "Some Files Are Ignored"
Step 4: git push -u origin master
The changes will occur in next commit from head revision.
Done!

Last Modified: 2 years ago