GitHub doesn't let you create empty folders, but you can add one by uploading a file inside it

GitHub's file system works differently than your computer's. You cannot create a folder and leave it empty — GitHub only tracks files, not folders. To add a folder to your repository, you create a file inside that folder. GitHub automatically creates the folder structure when you do.

The most common approach is to add a placeholder file (usually named .gitkeep) inside the folder you want to create. This tells GitHub to preserve the folder even if it has no other files yet. Once the folder exists, you can add real files to it later.

Key Takeaways

  • Create a folder by uploading a file with a path that includes the folder name, such as my-folder/filename.txt.
  • Use a .gitkeep file as a placeholder if you want a folder to exist but have no files to put in it yet.
  • You can add folders through GitHub's web interface by clicking "Add file" and typing the folder path, or through Git commands on your computer.
  • Nested folders (folders inside folders) work the same way — just use forward slashes in the file path, like folder1/folder2/file.txt.

Adding a folder through GitHub's web interface

Open your repository on GitHub.com and click the "Add file" button near the top right. Select "Create new file" from the dropdown menu.

In the filename field at the top, type the folder name followed by a forward slash and a filename. For example, type docs/README.md to create a folder called docs with a file called README.md inside it. GitHub will create the folder automatically when you commit the file.

Add content to the file in the editor below, then scroll down and click "Commit new file". The folder now exists in your repository.

Using .gitkeep to preserve empty folders

If you want a folder to exist but don't have a file to put in it yet, create a file named .gitkeep inside it. This is a convention in Git projects — the file itself does nothing, but its presence tells Git to track the folder.

Follow the same steps as above: click "Add file" → "Create new file", then type folder-name/.gitkeep in the filename field. Leave the file content empty and commit. The folder will now appear in your repository even though it contains no actual files.

Later, when you add a real file to that folder, you can delete the .gitkeep file if you want. The folder will remain because it now contains another file.

Adding folders from your computer using Git

If you work with Git on your computer, you can add folders the same way. Create the folder structure on your hard drive, add files to it, then use these commands in your terminal or command prompt.

First, navigate to your repository folder and stage the files: git add folder-name/. Then commit them: git commit -m "Add folder-name". Finally, push to GitHub: git push origin main (or master if that is your default branch).

Git will automatically create the folder structure on GitHub when you push. You do not need to create the folder separately.

Creating nested folders (folders within folders)

You can create multiple levels of folders at once by using forward slashes in the file path. For example, typing src/components/buttons/button.js creates three folders — src, components, and buttons — with button.js inside the innermost one.

This works the same way whether you are using GitHub's web interface or Git commands on your computer. GitHub creates all the intermediate folders automatically.

What happens if you delete all files from a folder

If a folder contains only one file and you delete that file, the folder disappears from GitHub. This is because GitHub only tracks files, not empty folders. If you want the folder to remain, add a .gitkeep file to it before deleting the last real file.

Alternatively, if you are using Git on your computer, you can use git rm folder-name/filename to remove the file while keeping the folder structure locally, then add .gitkeep before pushing.

Organizing your repository with folders

Common folder structures include docs for documentation, src for source code, tests for test files, and assets for images or other resources. You can create as many folders and subfolders as your project needs.

Keeping files organized in folders makes repositories easier to navigate, especially as projects grow. Most open-source projects follow similar patterns, so new contributors can find things quickly.

Frequently Asked Questions

Can I create a completely empty folder in GitHub?

No. GitHub only stores files, not empty folders. If you want a folder to exist, it must contain at least one file. Use .gitkeep as a placeholder if you need the folder structure but have no files yet.

What is the difference between .gitkeep and .gitignore?

.gitkeep is a placeholder file that preserves an empty folder. .gitignore is a configuration file that tells Git which files to ignore and not track. They serve different purposes and are not interchangeable.

Do I need to delete .gitkeep before adding real files?

No. You can leave .gitkeep in the folder alongside other files, or delete it once real files are there. It does not affect how your project works — it is purely a convention to keep folders organized.

Can I rename a folder after creating it?

Yes, but the easiest way is to create the new folder structure with your files inside it, then delete the old folder. On your computer using Git, you can also use git mv old-folder-name new-folder-name to rename it.

What if I type the folder path wrong when creating a file?

You can delete the file and create it again with the correct path. Go to the file in your repository, click the delete button (trash icon), commit the deletion, then create a new file with the correct folder path.