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! 🙂