How to Ignore Files in a Git Repository that have Already been Declared in .gitignore

AuthorSumit Dey Sarkar

Pubish Date02 May 2023

categoryGit

In this tutorial we will Learn how to ignore files that have already been added to a Git repository using .gitignore file.

 

How to ignore files in a Git repository that have already been declared in .gitignore?

 

How to ignore files in a Git repository that have already been declared in .gitignore

If you've already added the files to your Git repository, adding them to the.gitignore file will not instantly remove them. You must use the git rm command to remove the files from your repository.

 

If you don't want to remove the files from your local repository but only ignore them from Git tracking, you can do it by follow following steps:

 

Step 1 - Add the file or directory name to the .gitignore file in the root directory of your repository.

 

 

Step 2 - Run the following command to clear the Git cache:

git rm -r --cached .

 

Step 3 - Commit the changes using the following command:

git commit -m "Removed ignored files"

 

Step 4 - Push the changes to your remote repository using the following command:

git push origin <branch-name>

 

This will remove the ignored files from being tracked by Git, but they will still be available on your local machine.

Comments 0

Leave a comment