Visual Studio 2022 Can't gitignore .vs folder

Luke Uhren 196 Reputation points
2022-02-23T19:19:50.093+00:00

Not sure what it is with Visual Studio 2022 but it seems it is not ignoring the .vs table in the .gitignore file in my repo. I use Azure Devops Repo and Visual Studio usually for my code management. I keep seeing these files no matter what I add to the .gitignore file though.

177250-image.png

I added this to the .gitignore, so is there something else I need to do as I am confused why this wouldn't be ignored.

This .gitignore file was automatically created by Microsoft(R) Visual Studio.

/.vs

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,130 questions
{count} votes

5 answers

Sort by: Most helpful
  1. Stokely 21 Reputation points
    2022-07-15T02:01:29.617+00:00

    This is more goofiness between Git and Microsoft that requires some new custom circus trick to work....but here it is!

    1. Make sure your Git repo has a .git and .gitignore folder and file.
    2. In the .gitignore file add the following lines with your Git project name to make sure your .vs folder is ignored:

    .vs/
    {yourgitprojectname}/.vs

    1. Delete the ".vs" folder. Be sure to leave the ".git folder intact. Realize when you do this you remove the Git-to-Visual Studio project connection, but your Git repo still exists.
    2. In the lower right corner of Visual Studio look for your Git repo again and click it. It should rebuild your .vs folder again. But now ".vs" will be ignored.
    3. Push your code to Azure, GitHub, etc. again. The ".vs" folder should not appear in your online repo and should be hidden. I use GitHub and it worked up there, so test your Azure.
    3 people found this answer helpful.

  2. Jason Goemaat 5 Reputation points
    2024-01-02T17:29:43.72+00:00

    If there are files that are already in the repository, you need to remove them first. The reason is in the docs: https://git-scm.com/docs/gitignore

    A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details.

    So if you add files to your repository and then add them to .gitignore, future commands will not affect those files but they will still be created locally when you clone the repository. Ignoring a file means that git commands looking for changes will ignore that path completely, but it doesn't actually remove those files from the repository. You can try using '--cached' with 'git rm' to remove them from the repository, but it's best to remove them first, commit the removal, then add the path to .gitignore so they won't be added back.

    1 person found this answer helpful.
    0 comments No comments

  3. Viorel 117.6K Reputation points
    2022-02-23T19:24:39.98+00:00

    Try adding .vs/

    Where are you seeing the files?

    0 comments No comments

  4. Luke Uhren 196 Reputation points
    2022-02-24T15:59:26.517+00:00

    It shows up in the .vs directory in the root of the repo. Example I added .vs/ and /.vs which doesn't work unless you can't actually have both.

    Just keep seeing these show up every time making changes
    177566-image.png

    0 comments No comments

  5. satya karki 986 Reputation points MVP
    2022-03-05T16:32:59.88+00:00

    Hi @Luke Uhren , You can try adding /.vs below way:

     YourProjectName/.vs  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.