How to Create a Folder in Github Repos in 4 Simple Steps

github create new folder illustration

Github is an incredible tool for storing, sharing, and learning code. Creating code repositories is a cinch but common methods of organization, like how to create a folder in Github, aren’t intuitive.

The process is super easy but it takes some getting used to compared to typical OS-approaches. Essentially, it’s a matter of typing in a forward slash to indicate folder structure. There are some gotchas, however, but below is a step-by-step walkthrough on how to add a folder in Github.

Overview

The steps for creating a folder in a GitHub repo are simple but not immediately clear. Two rules: you must have a repo and you can’t create empty folders. Provided you satisfy those conditions, the following steps will result in a new folder:

  1. Make sure you’re in an existing repository
  2. Click "creating a new file" if the repo is empty or Add file > Create a file if not.
  3. Type the name of the folder in the input field, followed by a forward slash character.
  4. Type the name of the new file you wish to create in the folder. Note: GitHub doesn’t allow the creation of empty folders.

Step 1: Have a Repository

The first step should be self-explanatory but let’s not assume anything. From your profile page, click the repositories tab > create new repository. Alternatively, you can navigate to an existing repo in which you want to create a new folder. It’s worth noting: you cannot use the forward-slash character when creating a new repository—it’s automatically replaced with a hyphen character as illustrated in the following image:

github repo sub directory creation
While it might be convenient in some cases, Github does not allow the creation of initial sub-folders when creating a new repo

Step 2: Click “creating a new file”

Once you’ve created a new repo, or selected an existing one, navigate to that repo. Once there, if the repo is empty, you will be shown several default messages illustrating various actions you can take. Among them, within the first option, is a hyperlink with the anchor text “creating a new file” as shown in the image directly below. Click it.

github create folder step 2 create new file
Clicking the “creating a new file” option will bring up the dialog needed to create new folders as well.

If you want to create a new folder in a repo with existing content you’ll be shown a slightly different screen. Rather than creating a new file, click the “Add File” and then select the “Create new file” option from the drop-down menu.

github add new folder existing repo
Clicking the Add File button will allow the required creation dialog to initialize

This step, as well as the one from a new repo, will both result in the correct new file creation dialog appearing.

Step 3: Use the Forward-Slash Character to Create a New Folder

After clicking the “creating a new file” link you’ll be taken to the file creation dialog. Here, you’ll be facing a blank input field where one typically types the name of the new file being created.

Type the desired name of your new folder followed by a forward slash. After the forward-slash character is detected, Github will automatically generate a new input field for the file, while recognizing the first input as a new folder name, as shown in the illustration below:

github create folder step 3 forward slash
Type the forward-slash character to signal GitHub to create a new folder, then continue typing a new file name

Once your folder name and new file name are correctly typed, scroll down to the bottom of the page and click the green “create file” button. Optionally, you can enter a commit message and description.

github new folder create file
The green “Create New File” button will be greyed out until a file name is entered

[alert type=white ]Note: GitHub will not allow the creation of an empty folder. You must create a file—even a blank one—or the [/alert]

Step 4: Confirm Folder Creation

If you completed each of the above steps, you should now have a new folder in your Github repo. this will be evidence by the repot url in the main navigation area along with the newly-created folder name in the secondary navigation area, as shown in the image below:

new github folder result
The result will produce a hyperlinked folder to which you can easily navigate and create new files/folders

Discussion

GitHub is an incredible tool for developers around the world. It’s amazing that so many of its features are free to use. Despite its magnificence, certain tasks like creating a new folder in a GitHub repository aren’t as straight-forward as one might think. Fortunately, at least in the case of sub-directory creation, there are workarounds that are simple enough!

alpharithms discord banner 1
Zαck West
Entrepreneur, programmer, designer, and lifelong learner. Can be found taking notes from Mother Nature when not hammering away at the keyboard.