.gitignore what should be ignored?

Published 2 years ago by jasonb

Hello,

What all should we be ignoring from the laravel 5 installation? .env composer.lock vendor

What about storage?

Anything else that may be a good idea/ -J

ixudra
ixudra
2 years ago (13,565 XP)

Hey Jason

First thing I see: do NOT ignore the composer.lock file, it's bad practice. For the explanation on this, I will refer you to a talk by Jordi Boggiano (creator of composer) on the subject - he can explain it much better than I can.

Here is a sample of the gitignore file I use on my projects. I won't claim that it's perfect, but it will get you started.

/bootstrap/compiled.php
/vendor


/build/logs
/build/coverage


/app/tests/_log


composer.phar


.DS_Store


/.idea
/_ide_helper.php


/app/config/packages
/public/packages


/node_modules


.env


jasonb

ok great. What do you think about storage/ ?

ixudra
ixudra
2 years ago (13,565 XP)

I would definitely add that in there. Now that you mention it, it's not in my .gitignore file, I'll have to change that ;-D

dberry
dberry
2 years ago (38,325 XP)

@jasonb , @Elimentz the directories under storage all already have the proper .gitignore in them so you don't need to add that to your root .gitignore.

If you add your own folder to storage, then just add a .gitignore in that directory:

*
!.gitignore
bashy
bashy
2 years ago (1,088,160 XP)

Storage is added but nothing inside folders are included since they have .gitignore files in.

anheru88

The storage folder you don't ignore, becouse in the folders has a .gitignore files, and you never push the storage files to the version controller.

sg1asgard

Try this too :)

https://www.gitignore.io/

ruhul
ruhul
1 year ago (7,290 XP)

It does not make sense to me that, why should I ignore vendor folder? I hope someone already has this explanation.

Pendo
Pendo
1 year ago (35,375 XP)

@ruhul: the vendor folder contains all project dependencies, these are installed using "composer install" on a fresh project. No need to upload them to git since their version management is not within your project.

tobia

On the other hand, if you gitignore the vendor folder, you won't be able to use Git for deployment (push to your server to update your website) because you will have to install and run composer on your server, which might not be optimal, or even allowed on some hosting servers.

Plus, if some repository suddenly goes away from the Internet or is modified or corrupted (it happens) then you won't be able to run your project anymore.

larsnieuwenhuizen

@tobia I understand what you're saying but i would strongly recommend you do not use git for deployments. Git is a versioning tool and not a deploy tool. There are a lot of tools which are better suited for deployment. I myself use Ansible for server provisioning and environment deploys.

Git should be used for what it is build for.. versioning. And you do not want to version 3rd party packages (aka vendor folder) or anything else that is useless to version (like compiled files etc...)

tnorthcutt

@sg1asgard https://www.gitignore.io/ produces a lock file for Laravel with composer.lock ignored, FWIW.

kreierson

I don't ignore my Vendor folder. Since I use Laravel Forge, it's nice to be able to push to a git repo then have Forge pull in the changes for me to update my website.

RomainLanz

@kreierson Your composer.lock file already manage to keep the same version of packages you use in production.

marlonZA

I am seeing a lot of comments directing 'good idea' at using git for deployment, and checking in binaries and vendors... No one can stop you, but this is bad practice and will catch up with you, if not in the project, somewhere else. Really listen to advice for a bit.

vendors, ignored. That's why deployment tools do composer install for you, even heroku.

Please sign in or create an account to participate in this conversation.