• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Create Folder In GitHub Repository

Thumbnail for Razvan LudosanuRazvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Published: 2/1/2024

About Terminus

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 .placeholder file within that directory.

For example, if you want to push an empty directory named config, you can start by creating it using the mkdir command:

 $ mkdir config

Run in Warp

Then you can create an empty .placeholder file within it using the touch command:

 $ touch config/.placeholder

Run in Warp

Finally, you can commit this new file to the repository using the following git commands:

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

Run in Warp

And finally push it out using git push origin

 $ git push origin main

Run in Warp

This will, by extension, also commit the config 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 README.md file instead of a .placeholder file, or any other empty file for that matter as long as it is tracked by Git.

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

Thumbnail for

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

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

A word on the .gitkeep file

In some cases, you might see developers using a .gitkeep file instead of a .placeholder or README.md file.

Since this file has not explicitly been prescribed by Git (it has no actual meaning, unlike the .gitignore 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 .git prefix should be reserved for files that Git itself officially uses.

Pushing multiple empty folders at once

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

 $ touch dir_1/dir_2/.placeholder

Run in Warp

Or you can create a .placeholder file in each directory using a brace expansion

 $ touch {dir_1,dir_2}/.placeholder

Run in Warp

Then use the aforementioned git-add, git-commit and git-push commands.

How to add a folder via the GitHub UI

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

 $ nvm install-latest-npm

Run in Warp

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

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

Thumbnail for
  1. 1. Type the directory name followed by a slash character (e.g. empty_folder/).

Thumbnail for
  1. 1. Type the file name.

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

Thumbnail for

How to upload a folder via the GitHub UI

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

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

Thumbnail for

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

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

Written by

Thumbnail for Razvan LudosanuRazvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Filed Under

Related Articles

Undo A Git Pull

How to effectively remove the commits introduced by a pull in Git using git-reset and preserve your local changes using git-stash. Also, how to cancel an unmerged pull request on GitHub.

Git
Thumbnail for Glory KimGlory Kim

Undo a Git Merge

How to rollback the changes introduced by a merge in Git by adding new opposite commits using git-revert and effectively removing commits using git-reset.

Git
Thumbnail for Philip WilkinsonPhilip Wilkinson

Prompt Show Git Branch In Prompt

Enhance your terminal with a custom Git prompt. Learn different ways to integrate this contextual info, from custom shell functions to Warp context chips and toolkits like Starship and P10K.

Git
Thumbnail for Gabriel ManricksGabriel Manricks

How To Remove Secrets From The Git History Remove Secrets From The Git History

Learn how to remove secrets from the Git history using the BFG and git-filter-repo command-line tools.

Git
Thumbnail for Utsav PoudelUtsav Poudel

Adding a Submodule in Git

This post will show you how to simply add a submodule to a local repository, clone a repository with a submodule, and work within a repository that has a submodule.

Git
Thumbnail for Philip WilkinsonPhilip Wilkinson

Undo a git push

This post will show you had to simply undo a git push three different ways.

Git
Thumbnail for Philip WilkinsonPhilip Wilkinson

Undo Git Add

Learn how to effectively use 'git add' to stage files in Git for committing, and discover two powerful methods to undo accidental stagings.

Git
Thumbnail for Glory KimGlory Kim

Undo a Git Rebase

This post will show you how to undo a rebase using git reset, git rebase and git revert

Git
Thumbnail for Philip WilkinsonPhilip Wilkinson

Git Push Origin

A breakdown of git push origin

Git
Thumbnail for Amanda KhooAmanda Khoo

Git Push Tags

This post will show you how to push a single tag, multiple tags, all tags, and tags with commits.

Git
Thumbnail for Philip WilkinsonPhilip Wilkinson

Undoing Git Commits

Explore ways to undo a commit, including git reset, git checkout, and git revert with git while preserving commit history.

Git
Thumbnail for Philip WilkinsonPhilip Wilkinson

Delete Local Git Branch

Learn how to delete local branches from your git repository, including ones with unmerged changes, as well as local remote-tracking branches.

Git
Thumbnail for Philip WilkinsonPhilip Wilkinson

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Thumbnail for null