Friday, October 16, 2026

Fixing Empty Folders Not Being Committed to Git Using .gitkeep

Git does not track empty folders, meaning they are not included in a push. If you create an empty folder, commit your changes, and push them to a remote repository, that folder will not exist when another developer clones or pulls the repository.

The stock solution is to create an empty file named .gitkeep inside each empty folder. Git tracks the .gitkeep file. This preserves the folder when the repository is pushed.

For example, where the audio and video folders are empty:

MyProject/
├── Resources/
│   ├── audio/
│   │   └── .gitkeep
│   └── video/
│       └── .gitkeep

The .gitkeep filename is a bog-standard convention. The .gitkeep filename is not part of the formal Git specification.

Real-World Example: Using Git to Manage CapCut Projects, Including Empty Folders

I encountered this problem while setting up Git repositories for remote video production teams using CapCut.

A stock CapCut project contains directories, such as the following:

ExampleCapCutProjectFolder/
├── qr_upload/
├── matting/
├── subdraft/
├── adjust_mask/
├── smart_crop/
└── Resources/
    ├── audioAlg/
    ├── videoAlg/
    └── digitalHuman/

In the standard CapCut project created by my team, the following folders were empty: qr_upload, matting, subdraft, adjust_mask, smart_crop, audioAlg, and videoAlg. CapCut will not open a project if these folders are missing, hence the issue being addressed. A cloned version of the repo must include the standard directory hierarchy.

The solution, as noted above, is to create a .gitkeep file in each empty directory:

ExampleCapCutProjectFolder/
├── qr_upload/
│   └── .gitkeep
├── matting/
│   └── .gitkeep
├── subdraft/
│   └── .gitkeep
├── adjust_mask/
│   └── .gitkeep
├── smart_crop/
│   └── .gitkeep
└── Resources/
    ├── audioAlg/
    │   └── .gitkeep
    ├── videoAlg/
    │   └── .gitkeep
    └── digitalHuman/

CapCut ignores the .gitkeep files, so using a .gitkeep file is a simple, albeit tedious, solution to the empty folder problem.

If only someone would write a blog on how to automate the creation of .gitkeep files in empty folders.


No comments :

Post a Comment