How to ignore changes to tracked files in your git repository

We will see how to ignore files that are already added previously to your git repository. Use the following commands to ignore changes to a tracked file.

Git ignore changes to tracked file

Use the following commands to first remove the tracked file from the Git versioning so we can start ignoring the changes to the tracked file, this does not delete or remove file from your system, only removes it from Git cache.

git rm --cached file_name_here
git commit -m "Your commit message here"

2 Methods to Ignore the Tracked file

You can use any one of the below methods.

Method 1: Using .gitignore file

Open .gitignore file and add your filename in it

// .gitignore
file_name_here

Method 2: Using .git/info/exclude file

Open .git/info/exclude file and add your filename in it to stop showing the changes in your file and start ignore the file.

// Open .git/info/exclude
file_name_here

Have a good day! 🙂

Author: Admin

Hello Friends, welcome to Hackerdays.com. I am the Admin of the site. I have worked as a software programmer for 7 years. I have started this site to learn as well as share whatever little knowledge i have gained over the period of time. If you wish to contact me, you can drop in an email to: admin[AT]hackerdays[DOT]com or you can also use the contact page. Thank you and I'll see you around.

Let us know your thoughts: