How to add a folder to a repository in GitHub

Adding folders and files to a project repository in GitHub is straightforward because of its user-friendly commands. Let’s see the steps to add a folder to a GitHub repository.

Adding a folder to a repository

To add a folder to a repository in GitHub, we would typically follow these steps:

  1. Open the terminal and switch to the repository directory on your machine.
  2. Create new folder(s) with the mkdir command.
mkdir nameOfFolder
  1. Add the folder to the repository using the following command.
git add . 
  1. After adding the folder, you can commit your changes with a meaningful message using the git commit command:
git commit -m "Added new folders to repository"
  1. Finally, push your changes to remote repository on GitHub using the git push command:
git push origin branchName

Here, origin refers to the default remote repository that a local repository is linked to, and branchName refers to the name of the branch that you want to push to the remote repository.

Note: Before executing the aforementioned commands, we need to use the git init command to initialize the repository if it has not already been done so.

After performing these steps, the new folder should be added to the GitHub repository.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved