Are you sure the files / directories you are talking about are ignored by git (they are in your .gitignore
file)? If that's not the case, here is the answer to your question:
Since they are bound to the environment you are working on, they should not be touched by git by any means. That's why you should not lose them if you checkout on another branch.
Only the composer.lock
, the package-lock.json
and the .env.example
should be versioned. Then, when you clone the repo from GitLab, you do a npm install
, a composer install
, you copy the .env.example
etc... in order to setup your dependencies, but the dependencies directories (eg. node_modules
) should not come from your repository.
Then after a while, let's imagine you want to update your Composer dependencies. You'll do a composer update
. Your composer.lock
file will be updated and will be committed to your repository.
Then, if somebody on another computer pulls your changes, he will only pull the newly updated composer.lock
file. He will then make a composer install
, which will install (or update if he already had installed them before) the dependencies from the composer.lock
into his vendor
folder.
I hope it helps you, feel free to ask more details in the comments :)