1

I checkout the same git repository multiple times on my machine, and open them on several VSCode instances. I do this because I work on different features/bugs simultaneously on the same repository.

This gets soon confusing which folder I have open, so I want to set a different color theme depending on each folder I open. I can usually do this via settings.json, but since I'm working on the same git repository on all folders, it'll conflict the settings. There's user's settings.json, but this only works globally as far as I know. Is there a solution to this?

rioV8
  • 24,506
  • 3
  • 32
  • 49
CookieEater
  • 2,237
  • 3
  • 29
  • 54
  • that is why they have branches in git, You can work on 100 featues/bugs at the same time, just commit what you have till this point, and use `git commit --amend` to add new stuff before you go to another branch, rebase the branches before merging. – rioV8 Jul 03 '23 at 07:05
  • if you need temporary change to `settings.json` for a branch you can use a named `stash`, same as the branch, you can apply a stash without removing it – rioV8 Jul 03 '23 at 07:09
  • I'd rather not change the settings.json in my working branch. I need to remember to undo the change. Or perhaps I can create a pre-push hook to make sure settings.json is not modified, but I wanted it to be automatic, and hoping VSCode or some extensions support this. – CookieEater Jul 03 '23 at 08:03
  • if you have constraints on the answers you want that are not stated in your question post, you need to fix that and state them in your question post. – starball Jul 03 '23 at 08:34
  • Use `git skip-worktree` https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree/13631525#1 – Dimava Jul 03 '23 at 08:52
  • every `.git` repo also has a local ignore file, I don't mean `.gitignore` that is pushed to the remote, it is a file in the `.git` folder, I don't know the name or the commands to manipulate, you can locally ignore `settings.json` without the need to modify `.gitignore` – rioV8 Jul 03 '23 at 09:38
  • specify in detail what you change in `settings.json` and what is different for the different branches/features/bugs – rioV8 Jul 03 '23 at 09:41
  • https://stackoverflow.com/q/1753070/9938317 - there is also a global `~/.gitignore` – rioV8 Jul 03 '23 at 09:43
  • as for your original goal, there's a similar question [here](https://stackoverflow.com/q/51571748/11107541), but it's about different projects, whereas yours is about different copies of the same project. – starball Jul 05 '23 at 10:11

3 Answers3

0

You could create a multi-root workspace for each checkout / git worktree, make your repo's root directory one of the root workspace folders of the multi-root workspace, and then set settings in the .code-workspace file. This approach has limitations: not all settings are available in the scope for .code-workspace files (see the scope section of https://code.visualstudio.com/api/references/contribution-points#Configuration-property-schema).


As for your original goal of having a different theme for different repository checkouts, unfortunately, workbench.colorTheme is not available for configuration at that scope. See also Different theme per window in Visual Studio Code, which suggests the following extensions which may be of use to you (I have no affiliation with these extensions):

starball
  • 20,030
  • 7
  • 43
  • 238
0

Each git worktree may have its own gitignored .code-workspace

  1. Add worktree.code-workspace to .gitignore and commit it.
  2. Create worktree.code-workspace in each worktree.
  3. Open it with VSCode and click "Open workspace" popup which appears if it was opened as file rather then as a workspace
  4. Use johnpapa.vscode-peacock or whatever VSCode extension to change workspace colors easy.
  5. If you already use .code-workspace with a bunch of configs and need your worktrees to sync their settings/whatever, git update-index --skip-worktree worktree.code-workspace. This will break if you change file on upstream, requiring you to manually merge, but will allow downstreaming .code-workspace changes
Dimava
  • 7,654
  • 1
  • 9
  • 24
-1

I do the following for this:

  1. Different branch
  2. Under that, we can edit settings.json.
  3. Since it's just a matter of visualisation but actually you don't have to commit it, then never include that file in git add command.
  4. Or if you are keen on using git add . (which basically adds all changes which is a bad practice we should honestly get rid of) then as mentioned in the comments, run git stash and then commit it.

This should help, let me know if something's missed by me. Thanks.

Keshav Biyani
  • 235
  • 1
  • 10
  • As I mentioned in my comment, that would require me to remember to not commit it or revert it later if I did. I'd want it to be automatic so it does not appear as a modified file in my git. – CookieEater Jul 03 '23 at 08:04