GitHub is a powerful platform for hosting and collaborating on code. As your project grows, organizing your files into folders (also called directories) is essential for maintaining clarity and structure.
In this guide, we’ll walk you through the different ways to create a folder in a GitHub repository, whether you’re working directly on GitHub or through Git on your local machine.
📁 What You Should Know About Folders in Git
Git itself doesn’t track empty folders. A folder must contain at least one file (like a README.md
or a placeholder) to be committed to the repository. This behavior applies whether you’re creating folders locally or through the GitHub web interface.
✅ Method 1: Create a Folder Using GitHub Web Interface
- Navigate to Your Repository
- Go to github.com and open your repository.
- Click on “Add file” > “Create new file”
- This is located near the top-right corner of the repository’s file list.
- Use a Slash to Define the Folder Name
- In the filename field, type:
folder-name/README.md
- This will create a folder named
folder-name
and add aREADME.md
file inside it.
- In the filename field, type:
- Add Content or Leave It Blank
- You can leave the file empty or add a short description.
- Commit the New File
- Scroll down and click “Commit new file” to create the folder and file.
✅ Method 2: Create a Folder Locally Using Git
- Open Terminal or Git Bash
- Navigate to Your Local Repository
cd path/to/your/local/repo
- Create a New Folder
mkdir new-folder
- Add a File to the Folder
Git requires at least one file, so add a file like this:echo "# Placeholder" > new-folder/README.md
- Stage, Commit, and Push
git add . git commit -m "Added new folder with README" git push origin main
Replacemain
with your branch name if different.
🚫 What Happens If the Folder Is Empty?
Git will not commit empty folders. To keep a folder in Git without real files, you can use a .gitkeep
file (a community convention):
touch new-folder/.gitkeep
Then stage and commit as usual.
🧼 Best Practices
- Use lowercase, hyphenated folder names for consistency (
e.g., user-data
, notUserData
). - Add a README.md file in key folders to explain their purpose.
- Avoid deeply nested folder structures unless necessary.
🔚 Conclusion
Creating a folder in a GitHub repository is simple, whether you’re using the web interface or your local machine. Just remember that Git doesn’t track empty folders—each folder must contain at least one file to be committed.
By organizing your project with clear, purposeful folders, you make it easier for collaborators (and your future self) to understand and navigate your codebase.