Physical AI News (Japan)

Physical AI, robotics and compute — reported from Japan.

日本語
· Industry· 日本語で読む

How to Keep Empty Folders in GitHub: .gitkeep and .gitignore Settings

A published gist explains how to handle empty folders in GitHub. It shows how to place a 0KB “.gitkeep” file in an empty directory. It also includes an example .gitignore setup that ignores files in a folder while keeping only .gitkeep.

Key facts

  • The gist shows how to create a 0KB “.gitkeep” file inside a folder to keep an empty folder.
  • The bash example targets empty directories and excludes those under “.git.”
  • The gist includes a .gitignore example that ignores a folder’s contents and makes an exception with “!FOLDER_NAME/.gitkeep.”

What happened

The gist explains how to create a 0KB “.gitkeep” file in a target folder to keep an empty folder in GitHub. It also provides bash and PowerShell commands for creating files in empty directories in a project.

Why it matters

The gist distinguishes between keeping an empty folder and keeping a folder while ignoring its contents, and provides bash and PowerShell examples as well as a .gitignore setup. Because the commands do not target the same directories, users need to check the folder structure.

Analysis

The gist covers two cases: keeping an empty folder and keeping a folder while ignoring the files inside it. In the first case, a “.gitkeep” file is created in the empty directory. In the second, .gitignore includes both a rule to ignore the folder’s contents and a rule to exempt that file from being ignored. Simply placing a file and combining it with ignore rules serve different purposes; the configuration example spells out the conditions for the latter. The scope of the bulk-creation commands also warrants attention. The gist’s bash example uses “-empty” and targets only empty directories. The PowerShell example, by contrast, recursively retrieves directories and creates files in them; it does not include a condition limiting the command to empty directories. Thus, although the text presents both as examples of the same task, they do not target the same range of directories. Users should check the targets before running the commands, depending on their needs. The .gitignore example uses “FOLDER_NAME/*” to target the folder’s contents and “!FOLDER_NAME/.gitkeep” to specify an exception. When using it, the key is to confirm that the rules apply to the intended locations and files, including after replacing the placeholder with the target folder’s name. The gist provides commands and configuration examples, but does not explain behavior in different execution environments or how to verify the settings. In particular, the difference in scope between the bash and PowerShell examples determines which directories receive files during bulk creation.

Details

The bash example is run from the project root and creates “.gitkeep” files in empty directories, excluding those under “.git.” The PowerShell example creates files with the same name in directories retrieved recursively. The gist also shows how to keep a folder while ignoring its contents by adding “FOLDER_NAME/*” to .gitignore and making an exception with “!FOLDER_NAME/.gitkeep.”

Sources

Translated from the Japanese original: /news/github-de-sora-forudaa-wo-nokosu-houhou-gitkeep-to-gitignore-5bd354. The Japanese version is authoritative if they differ.