Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix .vscode tracking in gitignore

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.

like image 378
Skye Brown Avatar asked Jul 24 '19 16:07

Skye Brown


People also ask

How do I ignore a .VS file?

Choose Tools > Options > Source Control > Perforce > Ignoring Files. Set your 'Ignore List' preference, including the 'Ignore List' file name.


2 Answers

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.

like image 82
Raul Avatar answered Sep 30 '22 05:09

Raul


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

**/.vscode/
like image 21
m0j0 Avatar answered Sep 30 '22 05:09

m0j0