What happens, you are not using git correctly. There is absolutely no problem with creating a branch and deleting files and folders. When you return to the main branch, deleted files and folders will be restored, since they were not deleted from this branch.
What happens in your case is that you deleted the file / folders from git using the removal of the operating system, and not the "git rm" command. This is why git status tells them to be "remote". Also why files remain deleted when switching branches. git expects files to be there, but they are not.
Git status indicates that you are running "git add", but that does not work. Since the file no longer exists, running git add will fail. You may not notice, but the message will also tell you to run "git rm". You might think that you cannot do this because the file is gone, but it is not. The rm command will still be able to delete the file from the repo, even if you have already deleted it from the file system.
Another, and easier than you can do, do git add -A. The -A flag will say add to mark any deleted or added files.
Try this for a test:
git init test-delete cd test-delete touch filea mkdir dir_b touch dir_b/fileb git add . git commit -m "Initial commit" git checkout -b new_branch rm -rf dir_b git add -A git commit -m "deleted files from branch" (ls to prove files arent' there) git checkout master (ls to show files have been restored) git checkout new_branch (ls to show files are gone again)
source share