Visual Studio does not ignore files specified in the .gitignore file

create a git branch from a specific commit

Visual Studio does not ignore files specified in the .gitignore file

Related question: .gitignore file for the visual studio project is not working.

This post is to help developers or mostly beginners who are facing issues related to the .gitignore file. It might be possible that Visual Studio or any other git tools like git CLI or TortoiseGit does not ignore files specified in the .gitignore file.

First thing first: Always add a .gitignore file first to your repository and then add other files to avoid this issue. You can download the sample .gitignore file from here=> Sample .gitignore file.

[Quick Solution]

Open a command prompt or git base and navigate to the directory that contains your solution file (.sln), then perform the following steps:

Step 1: Remove all of the items from the Git index

git rm -r --cached . 

Step 2: Update the Git index according to the updated .gitignore file

git add .

Step 3: Commit changes ( you can also commit your changes from the visual studio)

git commit -am "Remove ignored files"

All done. For more details, you can visit here.

Where is the issue?

When you added some files to the git repository before adding a .gitignore file, you are facing this issue. The files are modified, meaning they were already in the git repository before you added the .gitignore file and so you cannot ‘ignore’ changes to them anymore now.

The above solution will remove all files that have been cached as being ‘tracked’, then re-add files based on the .gitignore file.

This solution helps me a lot and may help you as well. Hope you enjoy the post. Happy coding!

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this post useful...

Share this post on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?