DEV Community

mostafalaravel
mostafalaravel

Posted on

Is it possible to put the

I work on a Laravel project.

When I'm in master branch and I checkout to another branch I get this message :

$ git checkout 34-my-new-branch
error: Your local changes to the following files would be overwritten by checkout:
        storage/framework/views/caaf62f72d38b7d25287398a507510f101a5b18e.php
Please commit your changes or stash them before you switch branches.
error: The following untracked working tree files would be overwritten by checkout:
        storage/framework/views/057722c519eb01b3d6b8aa1e28f4b226ca8e290e.php
        storage/framework/views/cfb3bd21bb7e616852dcb3192ea1826fb247979f.php
Please move or remove them before you switch branches.
Aborting

Enter fullscreen mode Exit fullscreen mode


`
Is there a way to prevent this message?

Top comments (7)

Collapse
 
rvxlab profile image
RVxLab

Add a .gitignore to storage/framework with the following content:

*
!.gitignore
Enter fullscreen mode Exit fullscreen mode

Those are compiled views and should never be committed in the first place, so you can safely remove them by then typing git rm -r --cached storage/framework/*.

Then commit.

Collapse
 
mostafalaravel profile image
mostafalaravel

my current .gitignore is like :

/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.testing
.env.backup
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.idea/
/public/img/avatars
/public/js
/public/css
Enter fullscreen mode Exit fullscreen mode


`

What should I add exactly ?

Collapse
 
sergeypodgornyy profile image
Sergey Podgornyy
/storage/*
/storage/!.gitignore
Enter fullscreen mode Exit fullscreen mode

and then run git rm -r --cached storage/framework/*

Thread Thread
 
rvxlab profile image
RVxLab

Not wrong. But also not what I said.

In case Mostafa didn’t know, it’s entire possible and legal to have multiple .gitignore files.

Thread Thread
 
sergeypodgornyy profile image
Sergey Podgornyy

Possible, but from my personal experience it is better to have a single .gitignore file to rule them all 🙂

Collapse
 
rvxlab profile image
RVxLab

Please re-read my comment, as I explained exactly what you need to do to fix this.

In case you didn’t know, it’s completely fine to have multiple .gitignore files.

Collapse
 
mostafalaravel profile image
mostafalaravel

okay Thanks RVxLab