Search code examples
phplaravelgitgitignore

.Gitignore Issue in laravel


I am trying to put session and logs directories into .gitignore file in my Laravel 10 project, but they are not ignored and are still tracked. I have tried to delete the folders and create them again, but that didn’t work.


Solution

  • Since your directories session and logs are already tracked, adding them to your .gitignore is not sufficient. You first need to remove them from the index, and make their content untracked once again.

    Here, I'm assuming that the directories session and logs are at the top level of your working directory.

    # removing the directories' content from the index
    git rm -r --cached session/ logs/
    

    Once the folders have been untracked, make sure that their corresponding patterns within the gitignore exhibit a trailing slash. This is to make sure that the patterns will match only directories. See the documentation for more details.

    If there is a separator at the end of the pattern then the pattern will only match directories

    #other patterns
    
    session/
    logs/
    
    #more patterns