Skip to content

Instantly share code, notes, and snippets.

@farhad-taran
Last active December 30, 2020 22:04
Show Gist options
  • Save farhad-taran/6f15f0dbd1a372781dacfb1009d36d4d to your computer and use it in GitHub Desktop.
Save farhad-taran/6f15f0dbd1a372781dacfb1009d36d4d to your computer and use it in GitHub Desktop.
using .gitignore to force an always empty directory and subdirectories for local development

sometimes we need a local folder in our repos that we use to put in development content into, but this is content that we dont necessarily want to be commited to our git history, so one way to acoid these unwanted files is to use git ignore.

you need to ignore files and folders recursively:

/local/** (if you only ignore /foo/, that is the folder, then no amount of '!' exclusion rule will work, since the foo/ folder itself is ignored: Git will stop there)

Then exclude folders from the ignore rules:

!/local/**/ Before whitelisting files like the .gitkeep

!/local/**/.gitkeep That works because the .gitkeep parent folders are excluded from the ignore rules.

this trick will allow you to have a folder and subfolders that will not have any files when commited to the repo but still hold the structure for when you want to put in test files and do local development

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment