Skip to content

Preserve open editor tabs when switching git branches #284876

@JoshuaKemmerer

Description

@JoshuaKemmerer

Description

When switching git branches in VS Code (either via the command line or VS Code's git UI), VS Code automatically restores the editor state (open files/tabs) from the last time that branch was checked out. This causes the currently open editor tabs to be replaced with previously viewed files from the target branch.

Desired Behavior

Users should be able to switch branches while preserving the currently open editor tabs, allowing them to continue viewing the same files in different branch contexts. There should be a setting that allows this functionality to be toggled, or a command that modifies the branch-switching behavior on an as-needed basis.

Current Behavior

  1. User has files A, B, C open while on branch feature-branch
  2. User switches to branch main/default
  3. VS Code closes files A, B, C and opens files X, Y, Z (which were open the last time main/default was checked out)
  4. User wants to keep A, B, C open and just switch the branch context

Expected Behavior

When switching branches, the open editor tabs remain the same, and only the file contents update to reflect the branch being checked out.

Use Case

This is particularly useful when comparing changes between branches or when needing to view the same files across different branches without losing your editor state.

Workarounds Attempted

  • Searched for and attempted to use relevant VS Code settings (e.g., window.restoreWindows, scm.preserveContextAcrossCheckouts) - none control this specific behavior
  • Branch-specific editor state restoration appears to be hardcoded behavior in VS Code

Environment

  • OS: macOS
  • VS Code: Latest

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions