708

I'm trying to determine what the .vscode folder contains, so I can determine whether I should commit it to source control.

In a fresh project, the folder is empty, except the settings.json file. What kind of things would go into this folder? Is it machine-specific, developer-specific like the .vs folder (and thus not something that needs to be committed)? Or should all developers share this single folder between them *and thus it should be committed)?

The comment at the top of the file .vscode/settings.json states:

// Place your settings in this file to overwrite default and user settings. { } 

This seems to imply that the folder should contain project-specific settings and thus be included in source.

4
  • If you start a project in Visual Studio and then commit it there should be a proper (at least typical) start .gitignore FE. If it's meant to be there it probably will be. You can also reference this which I've used without issue. Commented Oct 6, 2015 at 8:18
  • 5
    A good idea, @ChiefTwoPencils! For the record, the default .gitignore that Visual Studio creates does have .vscode folder excluded at this point in time. But since VS Code is itself rather new, they might have not gotten around to it yet. I've left the folder untracked for now while I get more info on it. Commented Oct 6, 2015 at 8:27
  • 2
    If you're reading this, subscribe to github.com/microsoft/vscode/issues/15909 and maybe one day you'll be happy 🙂 Commented Feb 3, 2022 at 18:20
  • The visualstudio.uservoice.com link is broken: "This UserVoice instance is no longer available." Commented Sep 12 at 22:07

10 Answers 10

591

Commit the .vscode folder if you want to share settings, task configuration and debug configuration with the team. I think generally it makes sense to share settings (e.g. whitespace vs tabs) with the team if you want to enforce settings in a team. We in the VS Code team share debug and task specific settings as well because we want our team to have the same set of debug targets and task targets for VS Code.

Btw you do not need to have a .vscode folder in your project for settings. You can also configure settings on a user level.

Sign up to request clarification or add additional context in comments.

14 Comments

If you want to share file-level settings like "whitespace vs. tabs" then you should look at a cross-editor solution like EditorConfig instead.
This directory has a subdirectory "chrome" of 80 MB size. Are you sure this should be committed to the repository?
You must not be using VSCode for something like a python project where the workspace settings are going to have environment specific python paths for things like VirtualEnv or Anaconda environments. Checking these files in sounds like a huge problem for most scenarios. Check in a sample/default file instead.
So, this popular answer seems to be just wrong/incomplete.
Doesn't this limit developers choice of IDE?
|
275

Commit some files in .vscode folder

Recommendation is to generally exclude .vscode folder, but leave select JSON files that allow other developers to receive shared settings. If included, these settings will be enforced at the folder level (they are set whenever a commit is checked out).

Examples of settings to include:

  • Language specific test configurations to run the test suite(s) (settings.json)
  • Extension settings for linters and code formatting tools to enforce the language rules used in this repo (settings.json)
  • Run and debug configurations (launch.json)
  • Shared tasks - if managed with VS Code (tasks.json)

Note that some settings can be stored in the user settings or workspace file, or transferred to it from the .vscode folder. See below.


Sample .gitignore code

Here are the settings, as suggested at https://gitignore.io. You can search for "VisualStudioCode" there to get the latest recommended .gitignore file. I use this website as a starting point for .gitignore for most of my new repos:

# Created by https://www.gitignore.io/api/visualstudiocode # Edit at https://www.gitignore.io/?templates=visualstudiocode ### VisualStudioCode ### .vscode/* # Maybe .vscode/**/* instead - see comments !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json ### Visual Studio Code Patch ### # Ignore all local history of files **/.history # End of https://www.gitignore.io/api/visualstudiocode 

In the above .gitignore file, the .vscode/* line (note: some debate on whether the * should be included - see comments; .vscode/**/* may be better to ignore nested folders as well) says to exclude everything in the .vscode folder, but then the !.vscode/a_specific_file lines tell git to "not" ignore some specific files in that folder (settings.json, launch.json, etc.). The end result is that everything is excluded in the .vscode folder except for the files specifically named in one of those other lines.


Other Factors

Including the .vscode folder in your repo doesn't actually hurt anyone that uses a different IDE (or text/code editor).

However, it may cause issues for other people using VS Code, or some of the settings may not load properly, if these files include generic settings that require something specific to your environment - like the absolute path the repo is installed in. The key is to avoid saving settings that are custom to your local environment, only sharing those that can (or, in the case of this repo, should) be used by everyone.

For example, if IDE setting files have absolute paths to the repo or any files/libraries, etc., then that is bad, don't share. But if all the references are relative, then they should work for anyone using the repo (although, be careful about path specification differences between Windows/Unix..).


About User, Workspace, and Folder settings

Note: the settings files in the .vscode folder are generally updated when you make changes to the folder version of the settings, but this appears to depend on how individual extensions are coded, because I've run across multiple exceptions to this rule.

  • If you make changes to the user settings, they are usually stored elsewhere (location depends on OS settings, usually in a home directory).
  • If you make changes to the workspace settings, they are usually stored in the *.code-workspace file that you are currently using. If you don't have a workspace (you directly opened a folder instead), then they will likely go to the .vscode folder, but, overall, this may depend on the extension that owns the setting anyway.

So, you should generally put custom settings for your personal PC into the user settings, and put generic settings into the workspace or folder settings.

9 Comments

Better to do: !.vscode/settings.json.default Then mv settings.json to settings.json.default
the .vscode/* does not work for me, had adjusted to .vscode/
Changing to .vscode/ will generally undermine the re-included files - .vscode/* will ignore all files (but not subfolders). .vscode/ will ignore the entire folder, which also means git will ignore the re-inclusions. Or as the documentation puts it: It is not possible to re-include a file if a parent directory of that file is excluded.
By the looks of it, the majority of people here are really looking for: github.com/microsoft/vscode/issues/15909 (which hasn't been worked on).
@JimmiTh I don't think ".vscode/* will ignore all files (but not subfolders)" is true. I tried .vscode/* with !.vscode/settings.json and it ignored files in subdirectories of .vscode just fine.
|
78

Between commit/ignore, there is a third clever option: commit with the .default suffix.

For example, you can add settings.json to .gitignore, and commit settings.json.default, much like it is common practice (in my team) with .env files, where you remove the .default after you cloned a project.

I took this advice from the video [Should we] commit editor settings to version control? by Mattias Petter Johansson.

10 Comments

A settings.json.default makes sense but this is assuming your entire team is using vs code and your codebase is not being shared to a wider audience. I find that my open source projects on GitHub, I just make sure I add it to my default gitignore, because I don't want to force a particular IDE on my potential users of my codebase.
@jamescampbell Adding IDE-specific files almost never forces that IDE on anyone - it just gives them the option to get your common environment settings if they do happen to use that IDE. The bigger quesiton is whether those files are officially supported - i.e. intended to always be up-to-date and working. Theoretically you could have multiple IDE environment files for different IDEs all present without any conflicts.
@Quuxuu you put .default in .vscode. VSC doesn't recognize it. settings.json is in gitignore, so if team member wants to use the defaults - just copy settings.json.default to settings.json (new file, ignored by git). This way you can override it with your own personal preferences later without commiting changes.
@SentientFlesh I disagree that it is "bad practice". This is more a convention that a given team or project needs to decide. Per my prior comment, what is the harm? Also, it's more about whether a toolset is "officially supported" by the core dev team/maintainer.
The problem with committing a foo.default file then excluding the actual foo from source control is that the default version will drift over time -- you'll add something to the real file or make a significant update, then someone will check out the project, copy over the default, and wonder why it doesn't work. I came here hoping to find a different convention.
|
27

Why not just looking at the practice, other than the arguments around here?

One of the biggest project that keeps .vscode I found so far is Mozilla Firefox. It looks like the Firefox team shares their common tasks and recommended extensions.

So I guess it is not a bad idea to keep .vscode, as long as you know what you are doing.

2 Comments

We shouldn't do something just because a random great company uses that.
@NaserMirzaei True, and I did not say we should adopt it. But many random people say "no" here whereas it's not in practice in some organizations. Then it is a good signal that they might miss something in their arguments.
26
  • never commit .vscode/settings.json - with the weird exception of search.exclude . If you really need to, be very careful of putting only settings particular of your project that you want to enforce to other developers.
  • for validation, formatting, compilation use other files like package.json, .eslint, tsconfig.json, etc
  • The only .vscode that makes sense to include are complex launch configs for debugging.
  • Be careful, there could be a third party extension in your system that could put private information there !

What you can't do is copy & paste the whole settings.json contents file to .vscode/settings.json. I'm seeing some people doing this and committing the file is an atrocity. In that case you will not only break others workspace but worst, you will be enforcing settings to users that you shouldn't like aesthetics, UI, experience. You probably will break their environments because some are very system dependent. Imagine I have vision problems so my editor.* user settings are personalize and when I open your project the visuals change...

Summary: If you are serious don't commit .vscode/settings.json. In general, settings that could be useful for a particular project like validation, compilation, makes sense but in general you can use particular tools configuration files like .eslint, tsconfig.json, .gitignore, package.json. etc. I guess vscode authors just added the file for simplifying newcomer experience but if you want to be serious don't!

9 Comments

I feel your suggestion about .vscode/settings is too restrictive. Use .eslint or .editorconfig files if you can, but you should still check in .vscode/settings if you really do want a setting to be shared among all developers on a team/project
Matt, why do you assume that all other developers use vscode ? Could be people using webstorm, vim, sublime, that's why you should work with eslint, etc and not settings.json.
Again, checking in .vscode/settings make sense if your working on a team that uses vscode or you are working on a project where many developers use vscode. Not all of these settings have cross-editor equivalents
Worth noting that dotnet new gitignore DOES include .vscode/settings.json for tracking (among a few other files in .vscode/), so your suggestion to "never commit .vscode/settings.json" directly contradicts the MS blessed way of doing it.
Just as a specific counterexample: I had to commit settings.json because the Editorconfig extension for Code still does not support enforcing the quote_style property, and punts to setting the relevant properties declarations. You can have the linter enforce this, but autocomplete will still default to the wrong quotes so you wind up with a flag every time you use a suggested import.
|
15

The same as other answers: no.

As an illustration, consider the approach chosen by Git 2.19 (Q3 2018), which adds a script (in contrib/) to help users of Visual Studio Code work better with the Git codebase.

In other words, generate the .vscode content (if it does not yet exist), don't version it.

See commit 12861e2, commit 2a2cdd0, commit 5482f41, commit f2a3b68, commit 0f47f78, commit b4d991d, commit 58930fd, commit dee3382, commit 54c06c6 (30 Jul 2018) by Johannes Schindelin (dscho). (Merged by Junio C Hamano -- gitster -- in commit 30cf191, 15 Aug 2018)

contrib: add a script to initialize VS Code configuration

VS Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux. Among other languages, it has support for C/C++ via an extension, which offers to not only build and debug the code, but also Intellisense, i.e., code-aware completion and similar niceties.

This patch adds a script that helps set up the environment to work effectively with VS Code: simply run the Unix shell script contrib/vscode/init.sh, which creates the relevant files, and open the top level folder of Git's source code in VS Code.

2 Comments

How do I generate a launch.json automatically enough for the team members to have it?
@KansaiRobot I would complete the contrib/vscode/init.sh in order for that script to copy a launch.json template file, for your team members to adapt. Note: you also have (in the last version of VSCode) a global launch.json shared across your workspaces.
12

If you're finding it difficult to ignore .vscode/ without including any sub-file, you could just ignore the directory:

.vscode/ 

And then manually track the file you want:

git add -f .vscode/launch.json 

The -f adds files even when they're ignored. Once Git sees changes to file .vscode/launch.json, you'll be prompted to commit them, just like any other file.

This actually worked for me, because I experienced the same issue, trying to ignore the .vscode/ path, without including a sub-file, settings.json.

2 Comments

You can set .vscode/* and !.vscode/launch.json
Alternatively, you can commit the file first, then ignore it. And if you need to make changes, temporarily un-ignore it.
3

A simple way to keep your settings without committing it in your project Git repository is creating a workspace and add a folder into it.

When do you create a workspace, you need to save a file, code-workspace. This file contains custom settings; just save this file out of the Git repository, and it will be free to add .vscode into the .gitignore file.

Comments

2

Yes, you should. I used to be a big advocate of not pushing IDE configurations to Git. However, things have changed lately for good reasons. I was reading through the Angular 17 .gitignore file and found the following:

# They ignored Idea (WebStorm) completely .idea/ # However, they kept the following four files version controlled .vscode/* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json .history/* 

Comments

0

The answer is "no", because the .vscode folder is for this editor, and you shouldn’t push these personal settings to the repository in case of confusing others, so you can add it to your project's .gitignore file to ignore the changes.

5 Comments

I would disagree with your strict stance. As mentioned in the answer by @BenjaminPasero, you don't have to, but it makes sense in many cases, e.g. sharing task configuration. Of course, it's good to be mindful of one's teammates and not force preferences on them unnecessarily.
Yes, this is why we have separate user settings and workspace settings (the .vscode/settings.json file in a workspace): code.visualstudio.com/docs/getstarted/… Only things such as tool configuration go into the workspace settings
@RonaldZarīts .vscodefolder is about your own editor's setting and code styles,I think it's just for own use,so as I said before ,don't push the folder to git control flow.
@jialinwang Sorry, I already did. ;) Jokes aside, it also contains items that are useful to share, for instance in my project we have (1) launch.json - launch configurations for debugging which can be non-trivial to set up. (2) settings.json project level settings, like TypeScript compiler to use, whitespace rules, (3) tasks.json - build commands. You can choose to not share, but we find it useful.
@jialinwang No they aren't. They are folder-level settings. Not only should you include the top-level one, if you have any settings specific to sub-folders, you should also include those. The important thing is to keep your user preferences out of the folder-level settings (this is important for other reasons as well). The kind of things you should have in your folder-level settings should apply to the entire folder: formatters, linters, whitespace conventions (e.g. trim final trailing new lines, tab size...)...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.