How to Create a Folder in a GitHub Repository

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

  1. Navigate to Your Repository
  2. Click on “Add file” > “Create new file”
    • This is located near the top-right corner of the repository’s file list.
  3. 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 a README.md file inside it.
  4. Add Content or Leave It Blank
    • You can leave the file empty or add a short description.
  5. 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

  1. Open Terminal or Git Bash
  2. Navigate to Your Local Repository cd path/to/your/local/repo
  3. Create a New Folder mkdir new-folder
  4. Add a File to the Folder
    Git requires at least one file, so add a file like this: echo "# Placeholder" > new-folder/README.md
  5. Stage, Commit, and Push git add . git commit -m "Added new folder with README" git push origin main Replace main 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, not UserData).
  • 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.

Sharing Is Caring:

Leave a Comment