Terminus by Warp
Create Folder In GitHub Repository

Create Folder In GitHub Repository

Razvan Ludosanu
Razvan Ludosanu
Founder, learnbackend.dev

By default, Git is designed to track the content of only files. If a directory has no files in it, Git presumes there is nothing to be tracked. This means that directories exist in Git only implicitly through their contents.

The short answer

Since Git only tracks content, a common way for developers to push an (almost) empty directory to an initialized Git repository is to create an empty [.inline-code].placeholder[.inline-code] file within that directory.

For example, if you want to push an empty directory named [.inline-code]config[.inline-code], you can start by creating it using the [.inline-code]mkdir[.inline-code] command:

 $ mkdir config

Then you can create an empty [.inline-code].placeholder[.inline-code] file within it using the [.inline-code]touch[.inline-code] command:

 $ touch config/.placeholder

Finally, you can commit this new file to the repository using the following [.inline-code]git[.inline-code] commands:

$ git add config/.placeholder
$ git commit -m "Create empty config directory"

And finally push it out using [.inline-code]git push origin[.inline-code]

 $ git push origin main

This will, by extension, also commit the [.inline-code]config[.inline-code] directory to preserve the file structure of your repository.

Note that although the result is the same, it is also possible to use an empty [.inline-code]README.md[.inline-code] file instead of a [.inline-code].placeholder[.inline-code] file, or any other empty file for that matter as long as it is tracked by Git.

[#easily-recall-with-ai]Easily retrieve this command using Warp’s AI Command Search[#easily-recall-with-ai]

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:

Entering [.inline-code]create and push empty directory in git[.inline-code] in the AI Command Search will prompt a one-line command that can then quickly be inserted into your shell by doing [.inline-code]CMD+ENTER[.inline-code].

Note that if your repository is already initialized, you can remove the [.inline-code]git init[.inline-code] instruction from the suggested command.

[#why-not-use-gitkeep]A word on the .gitkeep file[#why-not-use-gitkeep]

In some cases, you might see developers using a [.inline-code].gitkeep[.inline-code] file instead of a [.inline-code].placeholder[.inline-code] or [.inline-code]README.md[.inline-code] file.

Since this file has not explicitly been prescribed by Git (it has no actual meaning, unlike the [.inline-code].gitignore[.inline-code] file, for instance), I strongly discourage you from using it as it often leads to confusion, making people second guess its utility.

As a rule of thumb, the [.inline-code].git[.inline-code] prefix should be reserved for files that Git itself officially uses.

[#push-multiple-empty-folders]Pushing multiple empty folders at once[#push-multiple-empty-folders]

To push multiple empty folders at once on a Git repository, you can either create a [.inline-code].placeholder[.inline-code] file in the very last directory of the directory tree:

 $ touch dir_1/dir_2/.placeholder

Or you can create a [.inline-code].placeholder[.inline-code] file in each directory using a brace expansion

 $ touch {dir_1,dir_2}/.placeholder

Then use the aforementioned [.inline-code]git-add[.inline-code], [.inline-code]git-commit[.inline-code] and [.inline-code]git-push[.inline-code] commands.

[#create-folder]How to add a folder via the GitHub UI[#create-folder]

If you are using [.inline-code]nvm[.inline-code] as your Node.js version manager, you can update [.inline-code]npm[.inline-code] to the latest version supported by your current Node.js distribution in use with the following [.inline-code]nvm[.inline-code] command:

 $ nvm install-latest-npm

To create a new folder in Github, you can navigate to the desired repository, then:

  1. Click on the "Add file" button followed by the "Create new file" link in the dropdown menu.

  1. Type the directory name followed by a slash character (e.g. [.inline-code]empty_folder/[.inline-code]).

  1. Type the file name.

  1. Click on the "Commit changes" button.
  1. Write a commit message, select the branch to commit the files to, and click on the  "Commit changes" button to save the changes.

[#upload-folder]How to upload a folder via the GitHub UI[#upload-folder]

To create a new folder in Github, you can navigate to the desired repository, then:

  1. Click on the "Add file" button followed by the "Upload files" link in the dropdown menu.

  1. Drag the folder you want to upload in that area.

  1. Write a commit message, select the branch to commit the files to, and click on the "Commit changes" button to save the changes.

Experience the power of Warp

  • Write with an IDE-style editor
  • Easily navigate through output
  • Save commands to reuse later
  • Ask Warp AI to explain or debug
  • Customize keybindings and launch configs
  • Pick from preloaded themes or design your own
brew install --cask warp
Copied!
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist or join the Windows waitlist
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.