How to use Git and Github for Magento source control between local and shared web server

How to use Git and Github for Magento source control between local and shared web server

September 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to use Git and Github for Magento source control between local and shared web server

Mastering Git and GitHub for Magento Development: A Comprehensive Guide

As a seasoned developer working on a Magento solution, you’re likely seeking an efficient way to manage source control between your local environment and shared web servers. This guide will walk you through the process of utilizing Git and GitHub for seamless deployment of updates from your local copy to development (dev) and production (prod) servers.

Setting Up Your Development Environment with Git

First, ensure you have Git installed on your local machine and your Magento project initialized as a Git repository. If not already done:

cd /path/to/your/magento/project
git init

Now, add the files to the staging area:

git add .

Commit the changes with a meaningful commit message describing the state of the code:

git commit -m "Initial Magento setup"

Creating Branches for Local, Dev, and Prod Environments

You raised an excellent question about whether to use separate branches for local, dev, and prod. The answer is yes, this approach is highly recommended.

Create a new branch named ‘develop’ which will act as your integration branch:

git checkout -b develop

In the same manner, create branches for each of your environments (local, dev, and prod):

  • Local: git checkout -b local
  • Dev: git checkout -b dev
  • Prod: git checkout -b prod

Connecting to GitHub

To push your changes to GitHub:

  1. Log into Github and create a new repository named ‘magento-source’.

  2. On your terminal, add the remote repository by specifying its URL:

git remote add origin https://github.com/yourusername/magento-source.git
  1. Push your local branch to the remote repository:
git push -u origin develop

Deploying Changes from Local to Dev and Prod Servers

Deploying from Local to Dev Server

To deploy changes from your local branch (‘local’) to the dev server:

  1. On the dev server, clone the repository into a directory where you want to host the Magento site:
git clone https://github.com/yourusername/magento-source.git /path/to/your/dev/server/directory
  1. Navigate to this cloned directory on your dev server and switch to the ‘dev’ branch:
cd /path/to/your/dev/server/directory
git checkout develop
  1. Pull the latest changes from ‘local’ into the ‘dev’ environment:
git pull https://github.com/yourusername/magento-source.git local:local
  1. Deploy the application using your preferred deployment method (FTP, SSH, etc.).

Deploying from Dev to Prod Server

The process is similar for deploying changes from dev to prod:

  1. On the prod server, clone the repository into a directory where you want to host the Magento site.

  2. Switch to the ‘prod’ branch and perform a pull operation using the ‘dev’ branch as the source:

git checkout prod
git pull https://github.com/yourusername/magento-source.git dev:dev
  1. Deploy the application to the production server.

Best Practices for Git and Magento

Using Composer with Git

When installing dependencies via Composer, ensure you add the ‘composer.lock’ file to your repository:

git add composer.lock

This file should be committed as part of your repository to preserve the exact versions of your dependencies across all environments.

Keeping Your Development Server Up-to-Date

To keep your dev server synchronized with your local environment:

  1. On your dev server, checkout the ‘develop’ branch:
git checkout develop
  1. Perform a pull operation from your local repository:
git pull https://github.com/yourusername/magento-source.git local:local
  1. Deploy the updated application.

Conclusion

Utilizing Git and GitHub for Magento development is a powerful way to manage source control between different environments—from your local machine to shared web servers like dev and prod.

By following this guide, you’ve learned how to set up branches for each environment, push updates from your local copy to the remote repository, and deploy those changes across your development infrastructure.

Remember, Git is a powerful tool that allows you to track changes, collaborate with others (if needed), and roll back to previous states if necessary. It may take some time getting used to, but it’s well worth the effort in terms of maintaining the stability and integrity of your Magento projects.

Happy coding! If you have any further questions or need assistance with additional aspects of Magento development, don’t hesitate to visit Laravel Company for more resources and expert guidance.

Checkout Catalog Themes Configuration

Our network