Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Add New Folder to Existing GitHub Repo

· 5 min read · Home Tech

In this article
  1. Why You Might Need to Add a Folder
  2. Method 1: Add a Folder via the GitHub Website
  3. Method 2: Add a Folder Locally and Push
  4. What About Adding an Empty Folder?
  5. Choosing Between Web and Local Methods
  6. Common Mistakes and Troubleshooting
  7. Frequently Asked Questions

Yes, you can add a new folder to an existing GitHub repository directly on the GitHub website, or locally by creating the folder and pushing it with Git. The easiest method for a quick change is to use the "Add file" button on GitHub, which lets you create a folder by typing its name followed by a slash when naming a new file.

Why You Might Need to Add a Folder

Repositories grow and change. You might want to organize documentation into a docs/ folder, separate source code from tests, or add a directory for assets like images or data files. Adding a folder is a routine part of keeping a project tidy, and it doesn't require any special permissions beyond write access to the repository.

Method 1: Add a Folder via the GitHub Website

This is the quickest way when you only need to add one or two files inside a new folder. It works entirely in your browser.

  1. Go to the main page of your repository on GitHub.
  2. Click the Add file button (next to the green Code button) and select Create new file.
  3. In the Name your file... field, type the folder name followed by a forward slash, for example assets/.
  4. GitHub will show the path as assets/ and let you type a filename. Enter a name like logo.png or notes.txt.
  5. Add content to the file (or leave it empty if you just want a placeholder).
  6. Scroll down, add a commit message (e.g., "Add assets folder"), and click Commit new file.

The folder is created automatically because Git doesn't track empty folders. By adding a file, you ensure the folder exists in the repository.

Method 2: Add a Folder Locally and Push

If you already have the repository cloned on your computer, or you prefer to work with Git commands, follow these steps:

  1. Open a terminal in your local repository directory.
  2. Create the folder: mkdir new-folder (or use your file explorer).
  3. Add a file inside it, for example echo "# New folder" > new-folder/README.md.
  4. Stage the changes: git add new-folder/
  5. Commit: git commit -m "Add new-folder with README"
  6. Push to GitHub: git push origin main (or master, depending on your branch name).

This method is useful when you want to add many files at once or when you're already working locally.

What About Adding an Empty Folder?

Git does not track empty directories. If you create an empty folder locally and run git add ., the folder won't appear in the repository. To include an empty folder, you need to add a placeholder file inside it. A common convention is to add a file named .gitkeep (the name is arbitrary, but this is widely used). For example:

mkdir empty-folder
touch empty-folder/.gitkeep
git add empty-folder/.gitkeep
git commit -m "Add empty-folder with .gitkeep"
git push

On the GitHub website, you can't create a completely empty folder either; you must create at least one file inside it.

Choosing Between Web and Local Methods

Both methods achieve the same result. The web method is faster for a single file, but it creates a commit directly on the default branch, which may not be ideal if you use pull requests for review. The local method gives you more control: you can create multiple files, test your changes, and commit them with a clear message. If you're collaborating with others, consider creating a new branch locally and opening a pull request instead of committing directly to the main branch.

Common Mistakes and Troubleshooting

  • Folder not showing up: If you created an empty folder locally and pushed, it won't appear. Add a placeholder file.
  • Wrong branch: Make sure you're on the correct branch before committing. Use git branch to check.
  • Permission denied: If you get an error when pushing, you may not have write access to the repository. Fork it and make changes, then open a pull request.
  • Case sensitivity: On Windows or macOS, folder names are case-insensitive by default. If you rename a folder changing only the case, Git may not detect the change. Use git mv to rename properly.

Frequently Asked Questions

Can I add a folder with files using the GitHub website?

Yes, but you have to create each file individually. There's no multi-file upload for a new folder in a single step on the web. You can create the folder with one file, then use the "Upload files" button to add more files to that folder.

How do I add a folder to a repository that I don't own?

You can't make changes directly unless you have write access. Instead, fork the repository, add the folder to your fork, and then submit a pull request to the original repository.

What is the difference between a folder and a directory in Git?

None. In Git and GitHub, "folder" and "directory" are used interchangeably. Both refer to a container for files.

Does adding a folder affect the repository size?

Only the files inside the folder count toward the repository size. An empty folder (with a placeholder) adds negligible size. Be mindful of large files; GitHub warns if a file exceeds 50 MB and blocks files over 100 MB.

Can I add a folder using the GitHub desktop app?

Yes. In GitHub Desktop, you can create a new folder in your local repository using your file explorer, add files, and then commit and push. The app will show the changes and let you commit them.

Is there a limit to the number of folders I can add?

No, there is no limit. However, very deep nesting (many levels of subfolders) can make navigation cumbersome, and some tools may have path length limits. It's good practice to keep folder structures reasonably shallow.