luisfer
luisfer

Reputation: 2120

How to use Git With Laravel?

I'm pretty new to Git. I'm developing using PHP/Laravel on at least two machines; both Windows 10, let's call them office and home. I want to keep a sync environment on both. So I created an account on BitBucket.

I created my Laravel app using Laragon using the directory: d:\laragon\www\project

I created a clean remote repo in BitBucket and configured for use on the office PC, inside the project directory:

git init
git remote add origin https://...
git add .
git commit master
git push -u origin master

It copies some of the files to the remote repository. I understand this is because of the .gitignore file, and that's okay.

Now the thing is if I go to my home PC and do a:

git clone http://...

It will only get the non-ignored files. My question is, how do I have to configure the second development environment?

I tried to create a new app at the home's c:\laragon\www\project and then try to clone in this directory, but of course it says the directory is not empty, so does nothing.

Do I have to delete the .gitignore file the first time, so it syncs everything?

Upvotes: 1

Views: 8513

Answers (1)

Kenny Horna
Kenny Horna

Reputation: 14241

I'm assuming that you already have your second machine with the basic set up (php, composer, laravel, local server, node and so on..)

First of all you need to install your composer dependencies (listed in composer.json), to accomplish this run:

composer install

The .gitignore will only ignore.. well.. the desired ignored files, such as: node_modules and .env for example. To solve this, install your dependencies (listed in your package.json, that is not ignored by default) in your second machine using npm or yarn:

npm install
// or
yarn install

In the case of your .env file, I suggest you to clone the .env.example (creating the desired .env) and set your keys in every machine, because any of them can have a different setup.

Of course, your Laravel encryption key needs to be generated, so run:

php artisan key:generate

Finally, migrate your database (and populate it, in case you set up seeders) like this:

php artisan migrate --seed
// notice the '--seed' flag is used when you want to run your seeders

Upvotes: 4

Related Questions