16

I'm having trouble using .gitignore with my .vscode folder in my repository.

I added a rule in my .gitignore to ignore my entire .vscode/ folder:

# Visual Studio Code # 
.vscode/* 
.vscode/settings.json
!.vscode/settings.json 
!.vscode/tasks.json 
!.vscode/launch.json 
!.vscode/extensions.json 
.history.vscode/settings.json

Despite this, .vscode is still being tracked by my local git repository. I've tried a variety of different solutions including using git filter-branch to remove this folder from my git history and git rm --cached .vscode to clear my cache and re-commit my changes, but none of these solutions prevents the .vscode folder from being tracked by git.

When I run git status I keep getting this result:

On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .vscode/

nothing added to commit but untracked files present (use "git add" to track)

So far, I've worked around this by manually excluding this folder when I git add my changes.

Why is .vscode/ still being shown as untracked? If I were to git add . and git commit this, it would add this folder to my git history and eventually to my remote repository when I git push. I don't want this behavior to occur.

Penny Liu
  • 11,885
  • 5
  • 66
  • 81
Skye Brown
  • 237
  • 1
  • 3
  • 12
  • 3
    Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – EncryptedWatermelon Jul 24 '19 at 16:59
  • 1
    Your .gitignore file seems contradictory. You have ".vscode/settings.json", which means ignore that file, and then the next line you have the same thing preceded with an exclamation mark, which includes it again. – m0j0 Jul 24 '19 at 17:24
  • @m0j0 yes, I did this to explicitly try to ignore my settings.json file within .vscode when I was looking for different solutions – Skye Brown Jul 24 '19 at 17:56

3 Answers3

29

Had similar problem, turned out the files were added to my cache. Clearing it with below command worked.

git rm --cached .vscode/settings.json

Reference to the issue on github where I found the solution.

Raul
  • 621
  • 7
  • 18
21

Maybe try this in your .gitignore. This should ignore the entire .vscode directory, no matter where it is located.

**/.vscode/
m0j0
  • 3,064
  • 5
  • 26
  • 33
0

Happened for an Untracked git file .vscode/settings.json. Turned out to be a second line in our huge .gitignore file that was overriding the effort. In example below simply remove the bottom line.

Remember to re-stage and commit .gitgnore after the change.

# IDEs and editors
.settings/
.vscode/settings.json   -- Line I added that "was not working"
...

# IDE - VSCode
.vscode/*
!.vscode/settings.json  -- Line discovered that was overriding above (REMOVE)
...
SushiGuy
  • 1,323
  • 15
  • 19