0

I am refactoring a medium-sized code base in Visual Studio Code. I create a new branch, create some new folders, and move some files there. Whenever I commit my work and switch back to the main branch, the files in those folders are gone (as expected), but the empty folders remain!

It seems VSCode does not understand that these directories are part of the branch I am working on. Is there any way to solve this issue?

3
  • 2
    Does this answer your question? Switching branches in Git doesn't remove directories Commented Jan 22, 2022 at 17:35
  • Directories are not part of a branch. If they are present they are present. Git neither knows nor cares. Don't worry be happy. Commented Jan 22, 2022 at 19:03
  • Thanks @mkrieger1, that question is definitely related. It answers part of my question - but I had hoped that VSCode had implemented a smart solution for this. Apparently not :( Commented Jan 23, 2022 at 5:56

1 Answer 1

2

The problem is: VSCode will not do any type of git cleanup (git clean -fdxs for instance), because that might remove too many untracked elements (not just your empty folders from your other branch).
That would lead to some nasty surprises on each branch switch.

So said empty folders remain in your working tree and, as described here, any git clean should be done carefully.

Sign up to request clarification or add additional context in comments.

1 Comment

All right, that clears it up for me. I had hoped there was some setting in VSCode that could do a smart git clean, but it seems this is not the case. Thank you for the comprehensive answer!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.