This folder contains files. git can only clone to empty folders

I have a repository on Github which contains a few files. I want to clone the repository from the Github desktop. But it gives me an error saying - this folder contains files. git can only clone to empty folders. Could somebody explain what I should do? I want to be able to make changes to the repository through a code editor (like VS Code). Thank you.

When you try to clone a repo. The repo starts to copy from server to your machine, starting with .git folder.

In your case when this clone starts, there already exist a .git named folder in which folder you are trying to clone the folder.

SO what you can do?

  • You can simply move to an empty folder or any folder where .git name folder does’t exist in the root of that exact folder. Then clone the repo it will clone normally.
  • You can delete the old .git folder in the folder you are trying to clone. Then try to clone it will clone normally.
  • If the the old repo(the folder repo) and the remote repo(the one you are trying to clone) is same. Then you can simply run git pull origin This will update repo upstream with origin
1 Like

I had a folder by the name of “Java” on Github. I also had a folder on my machine by the same name. The two folders had different contents. The directory where I was trying to clone the folder on Github was the same directory that contained the Java folder (on my machine). This was causing a problem. The problem was solved when I deleted the Java folder on my machine.