When I clone a repo via the command Powershell command line in VS on our organization in GitHub, I get the files that I expect. Important note, at this step, I don't open the repo's folder in VS's solution explorer yet. For example (resulting behavior stated under command):
clone https://github.com/Our-Organization/our-repo.git -b temp
Gives me only the files in the temp branch. As shown with the ls command:
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2024/06/20 12:24 61 README.md
Next, I switch branches:
git checkout develop
Checks out the develop branch. It removes the files from the temp branch from my file system, and I only see the files from the develop branch. Now, I have the files on that branch:
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2024/06/20 12:29 .github
d----- 2024/06/20 12:29 someFolder1
d----- 2024/06/20 12:29 someFolder2
d----- 2024/06/20 12:29 someFolder3
d----- 2024/06/20 12:29 someFolder4
d----- 2024/06/20 12:29 someFolder5
d----- 2024/06/20 12:29 someFolder6
-a---- 2024/06/20 12:29 7256 .gitignore
-a---- 2024/06/20 12:29 194 somefile.txt
-a---- 2024/06/20 12:29 23172 solution.sln
-a---- 2024/06/20 12:29 63 README.md
Next, I switch back to the temp branch:
git checkout temp
Checks out the temp branch, removes any files that were in the develop branch, but not in the temp branch. As I expect, I now (again) only see the files in the temp branch:
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2024/06/20 12:32 61 README.md
The behavior described above is what I expect: When you check out a branch, you only have the files related to that specific branch.
This behavior changes, as soon as I open my local folder where I cloned the repo, using the VS 2022 (17.9.7) solution explorer.
Now, when I check out the temp branch, VS still keeps files from the develop branch, and indicates them as new untracked files on the temp branch!
Here is the Git Changes tab, showing the other branches' files, as new untracked files on the current branch:
Why does VS 2022 change the behavior of Git in this way? And how does one work around this? I don't want to keep files from a unrelated branch, as new untracked files, when switching to another branch.