0

VSCode shows in the status line which branch of git repository we are in. But switching the branch does nothing to the open editors.

My branches are usually working with different set of files and once I switch branches, I have to close all editors, and manually open the files for the another branch. Repeat for each git switch...

Is there a plugin for VSCode which can help with this?

rioV8
  • 24,506
  • 3
  • 32
  • 49
White Owl
  • 318
  • 1
  • 8
  • I don't think you can, since I don't think there is any correlation between branches and what files you have open. Note that switching branches might modify or delete an open file and if you haven't saved an edit, you might be prompted to do so. That's probably where the interesting part ends. Regarding this statement: "manually open **the files** for the another branch", how would VSCode know which files are "the files"? How do *you* know which files to open? – TTT Aug 29 '22 at 21:37
  • 1
    with extension [File Group](https://marketplace.visualstudio.com/items?itemName=rioj7.FileGroup) you can define set of files to load and load with a click in the View or with a key binding – rioV8 Aug 29 '22 at 21:41
  • @rioV8 I suppose some combination of that tool along with a script to create an on the fly group in the tool's config based on `git diff --name-only main HEAD` or similar might work. – TTT Aug 29 '22 at 21:46

1 Answers1

1

I have grown to use an extension: keep context.

Whenever you start a new branch, just remember to start a new task in the context, and it then saves your set of windows to it. Not perfect, but close to the functionality you are seeking.

Maybe it could be your next open-source contribution to make it change to the git repo!