How to force git to keep a directory but bypassing all the files that are inside it?



  • I have a certain folder and logs which is essential for the operation of my application. I'd like to add the same in my repository, for those who replicate don't want to be creating the same when doing it git clone. But the detail is that log files should not go to the repository, but only the folder.

    How to do that?



  • To do this in git just add a file .gitignore inside the desired folder and then determined that all files except the .gitignore will be ignored inside that folder.

    Structure:

    logs/
        .gitignore
    

    Content of .gitignore which is inside the folder logs:

    *
    !.gitignore
    

    Now just use the command git add logs/. Thus, the folder logs will be added to the repository, but the log files of this folder will be ignored.

    I usually use this a lot for upload folder that needs to exist, but I don't need the files that are in it.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2