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

GitHub's file structure works differently than your computer's file manager. You cannot create a folder and leave it empty — GitHub only recognizes folders that contain at least one file. To add a folder to your repository, you create the folder path while uploading a file into it. The folder appears automatically once the file is in place.

This works the same way whether you're using GitHub's web interface, GitHub Desktop, or the command line. The method you choose depends on whether you're already working on your computer or managing files directly on GitHub's website.

Key Takeaways

  • GitHub creates folders only when you upload a file into them — empty folders cannot exist in a repository.
  • You can add a folder through GitHub's website by typing the folder name during file upload, separated by a forward slash from the filename.
  • Using GitHub Desktop or the command line gives you more control if you're managing multiple files and folders at once.
  • A common practice is to add a README.md file inside new folders to keep them organized and document their purpose.

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 your folder name, then a forward slash, then the filename. For example, if you want a folder called images with a file inside it, type images/photo.jpg.

GitHub interprets the forward slash as a folder separator and creates the folder structure automatically. Add your file content (or paste it if you're uploading text), write a commit message describing what you're adding, and click Commit changes. The folder now exists in your repository with that file inside it.

This method works best when you're adding one or two files at a time. If you're organizing a larger project with multiple folders and files, using GitHub Desktop or the command line is faster.

Adding a folder through GitHub Desktop

If you've already cloned your repository to your computer using GitHub Desktop, you can create folders the normal way — right-click in your project folder and select New Folder. Name it whatever you need. Then add files into that folder using your file manager or text editor.

Once you've added files to the folder, GitHub Desktop will show the changes in its interface. You'll see the new folder and files listed under Changes. Write a summary of what you're adding in the commit message field, then click Commit to [branch name]. After that, click Push origin to send your changes to GitHub.com.

This approach feels more natural if you're used to organizing files on your computer, because you're doing exactly that — creating real folders on your hard drive, then syncing them to GitHub.

Adding a folder using the command line

If you work in the terminal or command prompt, navigate to your cloned repository and create a folder using the mkdir command. For example, type mkdir images to create a folder called images. Then add files into that folder using your text editor or by copying files from elsewhere on your computer.

Once your folder contains files, stage the changes by typing git add . (the period means "add everything in this directory"). Then commit with git commit -m "Add images folder", replacing the text in quotes with your own message. Finally, push to GitHub by typing git push.

The command line is the fastest method once you're comfortable with it, especially when you're managing many folders and files at once or automating tasks.

Why you might add a README file to new folders

Many developers add a README.md file inside new folders to document what goes there. This is optional but helpful, especially in larger projects. A README inside a folder might explain what files belong there, how to use them, or what they're for.

To add a README to a folder using the web interface, follow the same process as adding any file: click Add file, then Create new file, and type foldername/README.md. Write a short description of the folder's purpose in the file, then commit. This makes your repository easier to navigate for anyone reading it later, including yourself.

Organizing multiple folders at once

If you're setting up a project with several folders — like images, styles, scripts, and data — the command line or GitHub Desktop is more efficient than creating them one at a time through the web interface.

Using GitHub Desktop or the terminal, you can create all your folders on your computer first, add files to each one, then push everything to GitHub in a single commit. This keeps your commit history cleaner and makes it easier to undo changes if something goes wrong. If you're using the web interface, you'd have to repeat the upload process for each folder, which takes longer.

What happens if you try to delete a folder

GitHub doesn't have a direct "delete folder" button. To remove a folder, you delete all the files inside it. Once the last file is gone, the folder disappears automatically. You can do this through the web interface by opening each file and clicking the delete button, or through GitHub Desktop and the command line by deleting files locally and pushing the changes.

If a folder becomes empty by accident and you want to keep it, add a .gitkeep file inside it. This is an empty placeholder file that tells Git to track the folder even though it has no real content. Create it the same way you'd create any file: type foldername/.gitkeep in the filename field when adding a new file through the web interface.

Frequently Asked Questions

Can I create a folder without adding a file to it?

No. GitHub only recognizes folders that contain at least one file. If you need an empty folder to exist, add a .gitkeep file inside it as a placeholder. This empty file signals to Git that the folder should be tracked.

What's the difference between using the web interface and GitHub Desktop?

The web interface works from any computer with a browser and is good for quick changes. GitHub Desktop syncs with your computer's file system, so you can organize folders the normal way and push everything at once. Use the web interface for small edits and GitHub Desktop when you're managing a full project.

Do I have to use a forward slash to create folders?

Yes, the forward slash tells GitHub to create a folder structure. If you type images/photo.jpg, GitHub creates an images folder and puts photo.jpg inside it. Without the slash, it treats the whole thing as a single filename.

Can I create nested folders (folders inside folders)?

Yes. Type the full path with forward slashes: images/thumbnails/small.jpg creates an images folder, a thumbnails folder inside it, and puts small.jpg in the innermost folder. All folders are created automatically.