is there an easy way to git add a folder but none of its contents?
For example, if I'm developing a website with an images/ folder, I don't want the heavy images to be added to github, but I would like the folder to be added, because it makes copying the repo easier for other people / me on other computers.
One way to almost do this is to just modify my git-ignore file so that certain types of files (like jpegs) are ignored, but if all the files in my folder are jpegs, and all of those are ignored, then github will ignore the folder as well - which is not what I want.
Thus, I'm wondering if instead there is a one-line command that will add a folder but not its contents, ideally without having to add an empty placeholder file in every folder I want to add to github.
Thanks!
EDIT: From further reading, it looks like I do have to add a placeholder file like '.placeholder' or '.empty' to each folder that I want git to notice.
You should be able to drop a .gitignore
file in each dir you want to keep (and want to keep empty, if I'm understanding the intent). You could opt to have the file itself contain !.gitignore
, per https://stackoverflow.com/a/11579945/1795230. Then add/commit that .gitignore.
The presence of that file should keep your folder saved in git, and the entry to ignore everything that is not itself should keep the heavy images you mention our of the folder in your remote repo as well. So, a twofer, which is nice.
I'd say create something like a .keep file and then do "git add my/dir/.keep".
Git ignores empty folders, so there must be at least one file in your folder so git doesn't ignore it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With