How to Deploy a Laravel Project on GitHub: A Step-by-Step Guide
Hey there! If you’re working on a Laravel project, keeping it safe, organized, and shareable is crucial. That’s where GitHub comes in! Deploy Laravel project on GitHub helps with version control, collaboration, and deployment.
If you’re new to GitHub or Laravel, don’t worry! In this guide, I’ll walk you through the step-by-step process of deploying your Laravel project on GitHub. Let’s get started! 🚀
Step 1: Initialize Git in Your Laravel Project
Before pushing your Laravel project to GitHub, you need to initialize Git.
1. Open Your Terminal or Command Prompt
Navigate to your Laravel project folder using:
cd /path/to/your-laravel-project
2. Initialize a Git Repository
Run the following command to initialize Git in your project:
git init
This will create a hidden .git
folder inside your Laravel project, allowing Git to track changes.
Step 2: Add and Commit Your Project Files
Once Git is initialized, you need to add your project files for tracking.
1. Add All Files to Git
Run:
git add .
This stages all files in your Laravel project.
2. Commit the Files
Now, commit the added files with a meaningful message:
git commit -m "Initial commit - Laravel project setup"
Step 3: Create a GitHub Repository
Now, let’s create a repository on GitHub to store your project.
1. Go to GitHub
Visit GitHub and log in to your account.
2. Create a New Repository
- Click on the “+” icon (top right) → New repository
- Give your repository a name (e.g.,
my-laravel-project
) - Choose public or private
- DO NOT add a README, .gitignore, or license at this stage (we’ll do it manually)
- Click “Create repository”
Step 4: Push Your Laravel Project to GitHub
Now, link your local Laravel project to the GitHub repository.
1. Add the Remote Repository
Copy the GitHub repository link and run:
git remote add origin https://github.com/your-username/my-laravel-project.git
Replace your-username
with your actual GitHub username.
2. Push Your Code to GitHub
Run the following command to push your project to GitHub:
git push -u origin main
If you’re using master
instead of main
, use:
git push -u origin master
This will upload your Laravel project to GitHub!
Step 5: Set Up a .gitignore File (Recommended)
Laravel projects include cache, logs, vendor files, and environment variables that shouldn’t be pushed to GitHub. To prevent this, create a .gitignore
file in your project root and add:
/vendor
/node_modules
/storage
.env
.env.example
This ensures you don’t expose sensitive data on GitHub.
Step 6: Updating Your Laravel Project on GitHub
If you make changes to your Laravel project, update it on GitHub using:
git add .
git commit -m "Updated files"
git push origin main
This keeps your repository up to date with the latest changes.
By following these steps, you’ve successfully deployed your Laravel project on GitHub! This not only keeps your code safe but also allows collaboration with other developers.
If you’re looking for expert Laravel development services, CodeHunger is a great choice. They provide high-quality web development solutions tailored to your business needs.
👉 Now, go ahead and deploy your Laravel project on GitHub with confidence! 🚀