The Task Canvas extension lets you work with multiple code fragments without switching tabs.
v2.2.0 makes it easy to switch between tasks in different branches. If the Maintain Git branch option is enabled, Task Canvas saves the current branch name for each task and when you switch tasks it automatically switches branches: