1. Keep a placeholder for future content
Create uploads and an empty uploads/.gitkeep file in your editor, then stage that specific file:
git add -- uploads/.gitkeepVerify the index lists uploads/.gitkeep. The name .gitkeep is a convention, with no special Git behavior; a README explaining the directory’s purpose also works. It does not automatically ignore files added later.
git ls-files -- uploads/ 2. Keep the directory but ignore generated contents
For this alternative, create uploads/.gitignore with the two lines below instead of choosing the .gitkeep approach. * ignores contents and !.gitignore keeps the rule file eligible for tracking.
The rule file itself is the tracked placeholder, so the directory contains that file. This approach deliberately ignores future files until the rules are adjusted.
*
!.gitignore 3. Verify the chosen approach
For the .gitignore approach, stage its rule file:
git add -- uploads/.gitignoreCreate uploads/example.bin and check that its rule matches:
git check-ignore -v -- uploads/example.binList the index entries; uploads/.gitignore should appear and example.bin should not. If a parent rule excludes uploads itself, fix the parent rule first so Git can read the nested .gitignore.
git ls-files -- uploads/ For exact behavior and further details, consult the official references: Git documentation · git add documentation