622

Is the .vscode folder meant to be committed 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 be committed? Or should all developers share this folder 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. Also, this post on UserVoice seems to imply some typings would go in there, also suggesting that it should be committed.

3
  • 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. 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. 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 🙂
    – NikT
    Feb 3, 2022 at 18:20

9 Answers 9

535

Check in 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.

15
  • 196
    If you want to share file-level settings like "whitespace vs. tabs" then you should look at a cross-editor solution like EditorConfig instead.
    – Tanz87
    Oct 7, 2016 at 2:40
  • 4
    This directory has a subdirectory "chrome" of 80 MB size. Are you sure this should be committed to the repository?
    – ygoe
    Jun 1, 2017 at 8:50
  • 30
    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. Mar 27, 2018 at 18:14
  • 16
    So, this popular answer seems to be just wrong/incomplete.
    – ripper234
    Aug 17, 2018 at 13:02
  • 7
    Doesn't this limit developers choice of IDE? Nov 30, 2018 at 8:15
225

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

### VisualStudioCode 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.

7
  • 3
    Better to do: !.vscode/settings.json.default Then mv settings.json to settings.json.default
    – JohnFlux
    Jul 29, 2020 at 23:57
  • Yeah, that is another option. You can save a default/common version to the repo, then have people make a local version that they use after that point. It's hard to coordinate any changes that need to happen after that point forward, though.
    – LightCC
    Jul 30, 2020 at 2:02
  • 3
    the .vscode/* does not work for me, had adjusted to .vscode/
    – oleksa
    Feb 5, 2021 at 10:37
  • 4
    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.
    – JimmiTh
    May 16, 2021 at 0:07
  • 1
    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).
    – NikT
    Feb 3, 2022 at 18:18
72

Between commit/ignore there is third clever option: commit with .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.

I took this advice from video Commit editor settings to version control? by Mattias Petter Johansson

10
  • 8
    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.
    – james-see
    Sep 2, 2018 at 19:36
  • 17
    @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.
    – LightCC
    May 13, 2020 at 19:55
  • 1
    @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.
    – Tymek
    Aug 17, 2020 at 16:21
  • 1
    @LightCC It is still bad practice to leave IDE specific folders in open source projects. Sure it gives them the option to use my environment settings, but chances are they already have their own environment set up. It is best to keep it as agnostic as possible unless the project requires a specific IDE (plugins, etc.), even then I would probably .gitignore it. If anyone wants the IDE settings, they can always ask. The exception would be within a company for standardization purposes. Oct 29, 2020 at 1:28
  • 4
    @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.
    – LightCC
    Oct 29, 2020 at 15:11
28
  • 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
  • 12
    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 Dec 6, 2017 at 19:31
  • 4
    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.
    – cancerbero
    Dec 6, 2017 at 21:34
  • 5
    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 Dec 6, 2017 at 21:40
  • @MattBierner fair enough, if you are developing close source projects in a company that enforce the editor, but I don't think that's a common situation and specially in open source projects...
    – cancerbero
    Oct 25, 2018 at 2:44
  • The point about third party extensions is very valid - As an example I believe the MS SQL Extension will add connection profiles to the project/workspace settings.json if it exists - Although it doesn't store credentials it may be checking in server names etc.
    – Dan Harris
    May 15, 2019 at 13:15
23

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.

I will update this post when I see other big projects that shares .vscode.

2
  • 1
    We shouldn't do something just because a random great company uses that. Oct 7, 2022 at 15:53
  • 4
    @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.
    – Bumsik Kim
    Oct 9, 2022 at 12:21
17

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 VSCode 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.

10

Okay, this may seem pretty late, but 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 .vscode/launch.json you'll be prompted to commit them just like any other file.

this actually worked for me, caused i experience the same issue, trying to ignore the .vscode/ path, without including a sub-file settings.json

4

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

5
  • 24
    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. Sep 5, 2017 at 14:44
  • 2
    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 Sep 5, 2017 at 18:20
  • @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. Sep 7, 2017 at 9:28
  • 9
    @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. Sep 13, 2017 at 10:04
  • 1
    @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...)...
    – DylanYoung
    Feb 11, 2020 at 19:37
3

A simple way to keep your settings without commit it in your project git repository is creating a workspace and add 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 will be free to add .vscode into .gitignore file.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.