How to update the Laravel project

Daniel KoopLaravelLeave a Comment

When you create a new Laravel project with composer or the Laravel command line laravel new, there is no git repository installed in the main directory of the project. In some situations you do not require the latest version of the Laravel project, but if you do it is handy to know that you can easily update the Laravel project. Note: by project I do not mean the framework packages, but the files where you start before running composer update/install.

Update the Laravel project

I recommend to backup your database and Laravel files before you continue. Although following this guide should not provide problems, better safe than sorry.

1. Create a git repository

First, we will need to create a git repository. If you already have one, continue to step 2. You can create a git repository and add all current files using the following command:

git init
git add -A .
git commit -m "Initial commit before merging with the latest version of Laravel"

Do note that you can adjust the message to anything you want. If you are unfamiliar with git, you can check the documentation of git. I recommend to get familiar with git as this tool is an industrial standard for developing applications.

2. Add remote repository

Second, we need to to add the git repository of Laravel. One of the benefits of git is that you can have multiple remote repositories. This allows you to pull the original data from Laravel and use your own repositories to commit your own data. It is possible to configure a name for every remote git repository. Add the Laravel git remote repository with the name laravel to make clear where it is for. Also, it is likely that the name origin is already in use.

git remote add laravel git@github.com:laravel/laravel.git

3. Update the files

Simply run the following command to update the files. Note that git may complain that you need to merge some files. Do not worry, this is completely normal as it is likely that you have changed some files. Git will only complain about files that have changed by you and in the Laravel git repository. Change LARAVELVERSION to master if you are working on the latest version of Laravel or change it in your current Laravel version.

git pull laravel LARAVELVERSION

Summary how to update the Laravel project

In short, running the following code will update your Laravel installation. If it results in errors, you can always roll back to the first commit.