How to convince git that you’ve updated your gitignore file

With a couple of recent projects, I have been using Azure DevOps instead of my usual SVN for source control. This uses Git, and whilst the mind migration to Git has been generally painless, there have been a couple of points that keep tripping me up.

One of these is convincing Git that the .gitignore file has changed. When you start a new project in Visual Studio, and use Team Explorer to connect to Azure DevOps, it automatically adds everything to Git, including the bin and obj folders. You generally don’t want to put these under source control.

No problem, crack up the .gitignore file and add the following lines…

/.vs/MySolutionFolder/v16/Server/sqlite3
/.vs/MySolutionFolder
/MyProjectFolder/obj
/MyProjectFolder/bin/Debug/netcoreapp3.0

Visual Studio sometimes creates this for you, but even if it does, you still need to modify manually if you add a new project, as it doesn’t seem to do that for you.

So, you confidently hit the refresh button in the Team Explorer changes panel, expecting the files in these folders to go away… and they don’t. Hum.

After some searching, you come across the same Stack Overflow answer that you used last time, and wonder why you didn’t note it on your blog, so you’d be able to find it easily next time!

I’ve not worked out a way to do this via Team Explorer, so you need to use a Git Bash prompt and type the following…

git rm -r --cached .
git add .
git commit -m "fixed untracked files"

Note that this will delete any uncommitted changes, so you need to commit (or undo) those first.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.