Thursday, September 8, 2016

Git: How to check in a folder, but ignore its contents

Git does not let you to check in an empty folder, even if you are using it as a temp output location. How to work around it?

put this .gitignore into the folder, then git add .gitignore
*
*/
!.gitignore
The * line tells git to ignore all files in the folder, but !.gitignore tells git to still include the .gitignore file. This way, your local repository and any other clones of the repository all get both the empty folder and the .gitignore it needs.
May be obvious but also add */ to the git ignore to also ignore sub folders.

No comments:

Post a Comment