These instructions are for people using XAMPP. If you are using Codespaces follow these instructions https://github.com/CHT2520-web-prog/intro-to-laravel/blob/main/starting_assignment1.md instead.
First you need to create a Laravel project that you will manage using Git.
- In the shell/terminal navigate to your htdocs directory
- Create a new Laravel project (just like we did in the Introduction to Laravel practical) e.g.
composer create-project laravel/laravel assignment1
- This should set up a new Laravel project and install the dependencies.
- Go to https://git-scm.com/download/win
- Download 64-bit Git for Windows Portable. Make sure it is the portable version!
- Run the downloaded .exe file.
- It will ask you where you want to install git.
- Enter the drive letter of your USB stick followed by git e.g. D:\git
- Select 'ok'
- Git will install. It may take a bit of time, be patient.
- Open the git folder and start git-bash.exe.
- Go to https://git-scm.com/downloads.
- Select the latest version of Git for Windows/Mac.
- On Windows accept the default settings during the install.
- I can't test this for Mac.
- At the end of the install open git-bash.
Enter the following user settings, making sure you use your own student number and name
git config --global core.autocrlf true
git config --global user.email "u01234567@unimail.hud.ac.uk"
git config --global user.name "firstname lastname"
- You should now be set up with Git.
- Visit https://github.com/
- If you haven't already signed up, sign-up using your university email address.
- Once you've signed in, create a new repository.
- Name it 'assignment1'
- Make the visibility 'private' and use the default settings for the other values.
- Open git-bash
- Navigate to your Laravel Assignment Project e.g.
cd D:/xampp/htdocs/assignment1
On your home machine you can probably right-click in your project folder and open git-bash.
- Enter
ls
to check you are in the correct folder - One at a time, enter the following commands into git-bash, make sure you enter the URL of your repository.
git init
git branch -M main
git remote add origin https://github.com/username/change-this-for-your-repo
git add --all
git commit -m "Initial commit"
git push -u origin main
- A pop-up box may appear saying 'Select a credential helper'
- Select manager (you may be asked to login in to GitHub in a browser)
- Your files should upload to your GitHub repository
- Back in a web browser refresh your GitHub repository's homepage, you should find that all the files from your local repository have been uploaded to the remote.
You may get an error stating fatal: detected dubious ownership in repository. If you do you need to declare the folder as being safe e.g.
git config --global --add safe.directory D:/xampp/htdocs/assignment1
You will probably want to make further changes to your Laravel app. Everytime you've made a significant change e.g. added a new feature, you'll want to commit these changes and push them to your remote. To do this make sure git-bash is in your project folder and use the following commands:
git add --all
git commit -m "Enter a meaningful message that describes the new feature"
git push -u origin main
- Double check to make sure the remote contains the updated code.
Important Git doesn't upload all the files. This is intentional e.g. we don't want to move all files in the vendor folder, and by default we don't want to copy sensitive data like passwords so the .env file isn't copied. In your repo there is a special file call .gitignore that tells Git which files shouldn't be uploaded. Open this in VS Code to see how it specifies files and folder that should be ignored.
For example you might be working on a USB stick at university, you've uploaded your project to GitHub and then you want to continue working on it on your home PC.
- In your htdocs folder.
- Open git-bash in this folder enter the following command making sure you enter the URL of your repo.
git clone https://github.com/CHT2520/assignment-1-change-this-for-your-url
- The files should download to this folder
- Enter the following Composer command:
composer install
- The project's dependencies should now download and install.
- Change the DocumentRoot setting in your httpd.conf file to point to the public folder of your Laravel project.
- Save a copy of env.example as .env.
- Edit the .env file to specify the correct settings for the database on the local machine.
- Make sure your shell/terminal is in your Laravel project folder.
- Enter the following to set up your database tables
php artisan migrate:fresh --seed
- You should then be ready to continue with your work.
On your home PC you should now have the most up to date version of the project. So commit these changes and push to the remote e.g.
git add --all
git commit -m "Added a new feature"
git push -u origin main
- Check the changes can be viewed on the remote repository.
- On your USB
- Open git-bash
- navigate to your project folder.
- Enter the following
git pull origin main
- This will download the changes you made from home.
- Open the project in VS Code to check the changes are present.