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
.
mkdir myfolder
on Unix or make a new folder in Explorer on Windows..gitkeep
. Create it with touch myfolder/.gitkeep
or with your editor of choice.git add myfolder/.gitkeep
and git commit -m "Add empty folder placeholder"
.git push origin main
or replace main with your branch name.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.
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.
git status
shows nothing to commit then the placeholder was not added. Run git add
and check again..gitkeep
is a team choice. Some teams prefer a short README.md
inside the folder to explain its purpose.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.