How to Push an Empty Git Folder or Directory Example |Video upload date:  · Duration: PT3M53S  · Language: EN

Learn how to push an empty Git folder to a remote repository using a placeholder file and a few simple git commands for clean commits.

Keep empty folders in Git with .gitkeep and gitignore rules that work

Git has very specific tastes. It tracks files not folders, which means an empty directory is invisible to commits and remote repos. If you want a folder to exist in the repository so builds do not puke or collaborators do not get confused, add a tiny tracked file that says I belong here. That is the role of a placeholder like .gitkeep.

Quick steps that actually work

  • Create the folder with your file manager or the command line. For example use mkdir myfolder on Unix or make a new folder in Explorer on Windows.
  • Add a placeholder file inside the folder. A common choice is .gitkeep. Create it with touch myfolder/.gitkeep or with your editor of choice.
  • Stage and commit the placeholder with git add myfolder/.gitkeep and git commit -m "Add empty folder placeholder".
  • Push the commit to the remote branch with git push origin main or replace main with your branch name.

Why this works

Git stores content at the file level. When a folder contains a tracked file it becomes part of the commit tree and shows up on remote hosts like GitHub. .gitkeep is not special to Git. It is a convention that communicates intent so future humans know the folder is supposed to be there.

Alternative approach with gitignore rules

If you want a folder to be present but ignore most files inside it you can combine ignore rules with an allow rule. Put this in your .gitignore or a repo level ignore file

myfolder/*
!myfolder/.gitkeep

This tells Git to ignore everything under myfolder except the tracked .gitkeep file. Test your rules so at least one tracked file remains in each folder you want preserved.

Troubleshooting and practical tips

  • If git status shows nothing to commit then the placeholder was not added. Run git add and check again.
  • Use a tiny file. Do not commit a giant dummy binary just to keep a folder visible.
  • .gitkeep is a team choice. Some teams prefer a short README.md inside the folder to explain its purpose.
  • When you push the commit the remote repo will display the folder because the tracked file is included in the commit tree.

In short add a polite placeholder, commit it, push it, and move on. Your repository will stop playing hide and seek with empty folders and your teammates will thank you for not committing useless garbage.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.