Managing Your Project With Git


You aren't using a version control system.

You want to track code changes in your Laravel project and aren't sure what to use.


Use Git.

laravel:~$ cd myapp
laravel:~/myapp$ git init

That's it. Try checking the status.

laravel:~/myapp$ git status

You should see all the untracked files.

# On branch master
# Initial commit
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#   .gitattributes
#   .gitignore
#   app/
#   artisan
#   bootstrap/
#   composer.json
#   phpunit.xml
#   public/
#   server.php
#   util/
nothing added to commit but untracked files present (use "git add" to track)

Notice the file composer.lock is not tracked? You should edit .gitignore and removed the line that has composer.lock in it. This way you'll be tracking composer.lock too.

When you track composer.lock with your source code control system it allows you to do a composer update on your development machine and then, later, a composer install on your production machine. The composer install command will make sure all packages are the correct version as specified in the composer.lock file. Thus production uses not only the same packages, but the same versions of the packages as your development machine.

If you haven't configured Git with your name and email, it's easy.

laravel:~/myapp$ git config --global ""
laravel:~/myapp$ git config --global "Your Name"

You can add everything and commit it to your repository with two commands.

laravel:~/myapp$ git add .
laravel:~/myapp$ git commit -m "initial checkin"

And a final status will show you nothing's changed.

laravel:~/myapp$ git status

You should see the following.

# On branch master
nothing to commit, working directory clean


Laravel makes using Git easy.

Laravel automatically provides those hidden Git files to manage things correctly. This keeps you from checking in the entire vendor directory or all the log files in app/storage/logs.

You can follow your normal Git Workflow, update changes locally, push them to your remote repository (Github maybe?), and feel safe that everything is tracked and protected.

comments powered by Disqus