WordPress GitHub Integration

Apr 7, 2023

Share the news on

Let's start with the basics.

What is Version Control and why is vital?

If you're not familiar or are familiar with programming The concepts behind Git, version control and GitHub might seem weird to people who aren't familiar with them. Let us first go over each of the concepts in plain English.

Version Control

The process of controlling version control is that tracks and manages every changes that is made on the plan. This lets you look back, compare, and even reverse all of the project's changes and back to the previous version.

Git

Git is without doubt the most used software for managing versions. It's an effective software that has all the functions you require for collaboration, to manage the progress of your project and also to correct mistakes in the event of a need.

GitHub

The GitHub homepage, showing an illustration of a child in an astronaut costume in front of a large globe with glowing lines connecting country to country. The featured text reads "Where the world builds software".
GitHub

The benefits of integrating GitHub to WordPress

Imagine the possibility of being able take advantage of the control of versions that allow you to roll back older versions prior to the modification that has ruined your site as well as employing Git branching to create and verify that wild concept you came up with while coding for an afternoon.

Making the WordPress project in a group is another reason worth using WordPress as well as GitHub together. The group you work with may work on various aspects on the same website without having to shut your site you're working on for production.

When you're done, pull up the latest changes via main or any push button on your dashboard (keep looking).

For a summary of the many benefits of the GitHub and WordPress combination:

  • The normal workflow in WordPress development
  • Your website can be stopped from being down due to an error with a PHP script by rolling back an older versions
  • Collaboration with your friends and colleagues is possible with your website.

Beginning with Git, GitHub, and WordPress

In this part we'll show you how to develop themes or plugins using the platform of GitHub as well as WordPress.

Prior to starting, we must understand the basic idea that drives this method. The process will involve a local Git project. You'll create the first versions of your theme or plugin This is because they're among the most altered files inside your WordPress project. Then, you'll set up an GitHub repository, and then clone the repository inside your live install of the WordPress live install.

Let's go!

Step 1. Install Git onto Your Computer

This may seem a little overly obvious, however it is essential to install Git before working with your theme or plugin.

For installation, simply go onto the official download site to download the appropriate package for your operating system.

The official Git downloads page showing the macOS, Windows, and Linux download methods for the Git installer and the current version "2.34.1".
Git downloads

If you're using macOS or Linux it is possible that you need to execute a command with a terminal. Alternatively, when you're using Windows then you need to start on the wizard installer. This will take a few of minutes.

For confirmation that Git is running properly, type this command inside the terminal or on an appropriate command prompt:

git --version # git version "your version"

Step 2: Register to GitHub and then create a Repository

Create or log in to a GitHub account via the sign-up page of GitHub.

GitHub Sign Up page with the fields of email, password, and username.
GitHub Sign Up page.

Once you have signed in and registered, you can set up an account for the theme or plugin you have installed when you click the URL of the new repository.

GitHub new repo page with the fields Owner, Repository name, Description, Accessibility, README, and license files.
GitHub new repository

In the form, you should include the details of the repository and the title of the plugin you're going to develop, in my case: MyWordPressTheme, include a description of the project that provides an outline of the project. choose if your repository is either private or public (public that is, anyone has the ability to view it and create a fork of it, exclusive only you are granted access rights to gain access) then choose if you need to provide the user with a Readme as well as a licence from the beginning. Click on the Create Repository button..

Step 3: Set Up The Local WordPress Environment

Let's take a look at ways we can accomplish this using Dev.

Dev create New WordPress site with NGINX, MySql, and WordPress 5.8 option.
Dev.

Enter your website's Name, WordPress admin username, and password. Click"Create Site" and click the "Create Site" button.

My new WordPress site form with the fields of "Site name", "WordPress admin username", and "WordPress admin password" as well as the create site button.
New site.

This will automatically create a WordPress site in the folder /home/username/Dev/public/site-name, you can open it by clicking on the "site path" section.

Site info showing the path to the site WordPress files.
Information on the site.

You can examine the WordPress file structure within the management of files.

File manager showing the file structure of the site you just created, including some important files like the "wp-config.php" and the "index.php" files, as well as the subfolders "wp-content", "wp-includes", and "wp-admin".
WordPress file structure.

Your site is now fully functioning WordPress site listed on your website directory to serve as your home.

Step 4: Clone the GitHub Repo on your local Machine

The theme has an outside GitHub repository that contains the license and README files as well as license files. It's right time to add these files into your environment and get started on creating your theme.

In this instance the theme is being built, but you would do exact the same process when developing an application.

Navigate to your WordPress website's folder, and after that, enter the WP-contentdirectory this is the directory that houses all the themes and plugins available.

Once you've built the website using Dev It is necessary to add the path to your site to the Site Info and then go to the WordPress-contentfolder.

If you created your site using XAMPP, you would enter the /opt/lampp/htdocs/site/wp-content folder on Linux, and macOS, whereas on Windows you just need to go to the folder in which you extracted the WordPress source code.

When we create themes, go to the theme folder and copy the repository that we made on GitHub. Be sure to configure the SSH keys on GitHub for the event that you're not doing it.

The entire process is explained following using just a handful of instructions.

cd /home/username/Dev/public/site-name/wp-content/themes # or your wordpress site location git clone [email protected]:YourUsername/mywordpresstheme.git cd mywordpresstheme/

You can then create the style of the WordPress template or plugin.

Step 5: Add commit and push your changes to Your Remote Repo

You're ready to design your design.

A benefit of building a theme or plugin locally on your own machine is the ability to experiment with the program, make use of it, implement all adjustments, and experiment with all the methods you'd like to use. Therefore, go ahead and make the most impressive themes or plugins you're capable of.

But, if you're entirely familiar with the process of developing a WordPress theme, starting with scratch, here are some documents you need to look at.

  • index.php: The main file that defines the theme structure (required)
  • front-page.php: Creates the first view on the web site. It also displays the"/" (root) page
  • footer.php: Defines the footer on the website It's also used on numerous pages on the site.
  • functions.php: Allows to create specific functions
  • header.php: Defines the header
  • page.php: Pages created on the admin's website
  • screenshot.png: Image used to represent the theme's logo
  • single.php: Default mode used by posts.

If you need more information For more information, please look up the WordPress Developer's page for more information on Theme Development.

After having created your template, you're in a position to upload all modifications to GitHub.

Then, run git status to determine exactly what's changed.

Status of git... Not tracked files Untracked files(use "git add ..." to" to be included the files that will be committed) It's 404.php assets/ footer.php style.css404.php assetsfooter.php front-page.php assetsfooter.php front-page.php assets/footer.phpfront-page.php functions.php function.phpheader.php index.php page.php screenshot.png single.php style.cssindex.php index.phppage.php screenshot.png single.php style.cssscreenshot.png single.php style.cssstyle.css

You can then add all files that are within the directory currently and commit to them.

Add git .Then you commit it to git"Added theme files "Added theme files"

And lastly, upload all the modifications in the remote repository of the GitHub.

git push

6. SSH to Your WordPress Website , and then duplicate the Repo

The theme is built so it's the time to apply it in your current WordPress website.

Most hosting companies offer the ability for connecting to SSH to establish a connection to SSH. For more information, visit the official website of the service provider.

First, get first the SSH command and password.

My dashboard of the site "Test with WordPress" showing the password and SSH terminal command fields.
My site dashboard.

Paste the SSH commands into the command prompt. Input the password (using your authenticated in order to copy and transfer to copy the SSH password).

If you've authenticated successfully, you're now inside of the WordPress site's file structure.

Terminal connected via SSH to a  site.
SSH.

Now, you'll have to navigate to your site's folder, which is usually located on /www/name-site/public/. Go to the themes folder and then copy the repo to the folder.

cd /www/name-site/public/wp-content/themes git clone https://github.com/yourusername/MyWordPressTheme.git

We'll be making use of HTTP to clone the GitHub repo because we're not going to alter the theme of the server. We'll only create changes using our favorite code editor on our personal machine, and not in an ugly terminal editor that's on the server.

In the future, each when you'd like to download all the changes that have been made to remote repos into your server, you can do the following:

Pull git... Quick-forward 2 + 1front-page.php * 2- 1 changed file one deletion (+), one deletion(+)

Step 7: Log into the WordPress Administration and activate Your Theme.

https://yourdomain.com/wp-login.php

Once you have done that, head over to the appearancesection and activate your awesome theme.

WordPress admin dashboard with an arrow pointing to the "Activate" theme button.
Choose your preferred design.

If you're working with plugins then follow the exact procedure except that you place your plugin in the plugins/wp-contentfolder.

Congrats! You've built an awesome WordPress theme using Git, GitHub, and WordPress!

Utilizing My to integrate GitHub With WordPress

To assist in making WordPress the lives of WordPress developers simpler We're releasing GitHub Deployment for WordPress. GitHub Deployment allows you to connect directly to your GitHub account. It allows you to take advantage of the process of creating your website locally, making it easy to put the site live in just one mouse click.

All you require for this is an My account and the capability to utilize the control of versions in WordPress development.

Advantages of using GitHub deployment

The top advantages of this method are:

  1. Mixes the expertise of developing locally, then deploying it remotely on WordPress
  2. Lets you use all the features of the version control system using Git and GitHub
  3. Simpler than the manual technique that was previously described.
  4. Auto-deploy changes from your GitHub repo

Additionally, you need to download WordPress essential files and add them to your repository. It isn't enough to commit either a theme or plug-in since after the deployment, all staging files are deleted.

But, it's way easier than you might imagine.

Let's take a look at the ways you can join GitHub with WordPress with the help of My!

1. Create your GitHub Repo with all the WordPress Core Files

It's similar to the method used above, except it requires you to upload all documents of your WordPress installation in the GitHub repo.

Make an account on GitHub then copy it to your PC so that you are able to begin building the website in the local environment.

git clone [email protected]:youusername/WordPress-site.git # After you created the repo on GitHub
unzip path/to/wordpress/zip cp -a wordpress/. path/to/your/repo/

Notice how we extract our zip file in the directory currently in use and copying its contents into our repo using the special cp dot (/. ) syntax.

Your repo's structure should look something like this:

. +- .git + wp admin +- - wp-content includes in wp-content + .gitignore +- index.php +-- License-- license.txt +readme.html +- readme.html + README.md +-- wp-activate.php to activate the account... + wp-settings.php + wp-signup.php + wp-trackback.php +-- xmlrpc.ph

Change your project and once your project is complete, upload your new changes on the repo on GitHub: GitHub repo:

Include the git .andCommit using git with -m "Added WordPress files"

This is the place where you need to spend the majority the time. It will be clear that it's easy to integrate GitHub with WordPress.

Step 2: Design or Access a Web-based Site using My Dashboard. My Dashboard

If you've got an existing website you are able to bypass this step. If you're making your own website, you should be sure to create the website using a clean, safe background. This will take less time as compared to a full WordPress installation.

Go to your My dashboard Go to the Sitessection and then click the button to add a sitebutton. After completing the application, within a couple of hours, you'll have an unoccupied space which you are able to work from.

Add site modal with the
Include a site-specific modal.

Step 3: Change To a Staging Environment

For creating a staging area, go to your site's dashboard and click from the Environment option in the upper right corner of the page, and select staging from the drop-down menu.

's site page staging environment option.
The environment for staging.

Click on the create a staging environmentbutton. In accordance with the number of files you have in your live environment it might take longer or shorter to boot up. This is why it's suggested to start with an empty environment if you don't already have an online presence at the start.

Create a staging environment page with the title "My awesome  site", instructions about this feature, and an arrow pointing to the "Create a staging environment" button.
Set up a staging area.

When you've uploaded your repo into the staging environment, you are able to move it into in the real environment. You'll be able to see how this process works in the future.

Step 4: Log to the GitHub

For pulling a repository from GitHub, My needs access to your GitHub account. It's not a problem -it happens for every service that needs permissions to access the specific repository.

You'll need to go to the section for deploymentsection after you've created your staging space Then, click on the start setupbutton.

GitHub Deployment page in My, showing the "Begin setup" button.
Start setting up.

After that, you'll be directed to the GitHub authentication page which allows you to configure the deployment of your GitHub repo.

After you've finished you'll be in a position to choose the Organization(usually your personal account) from which you'd prefer to pull your repo's repository from. You can also select the repo within which you made your WordPress site, and finally, the branch you'd like to pull from (in most cases it's called "main").

Configure deployment modal with the checked "Auto deploy" option.
Configure deployment.

You can check for the auto deploy upon commitbox if you want My to to share every modification you make to the branch you chose.

Take care with this option, you will only need to make deployment automated when you're working on a specific branch for each aspect, and just committing your primary branch for merging these aspects.

Choose the Closebutton. Now, you can deploy your repo into your Staging environment.

 GitHub deployment page of the "My awesome  Site" showing the "Deploy now" button.
Start your deployment now.

It shouldn't take more than a two seconds to access your newly designed stage site. It is accessible through the Domainssection after clicking the "Open URL"link.

"My Awesome  Site" Domains section showing the Open URL link.
Open URL.

If, for any reason, you'd like to remove your My site from your repo, simply go to your change settingsoption and click on the Disconnectbutton.

Deployment modal showing the "Organization", "Repository", and "Branch to pull" fields, the auto-deploy checkbox, and the "Disconnect", "Cancel", and "Change deployment" buttons.
Connect the repo.

Stage 5: Click to Live

Click on the Environmental Actions and select "Push to live"option.

GitHub Deployment section showing the "Push to live" environmental action.
Living the dream.

You've come this far , then you're on the verge of an entirely functional website that can be that is being developed via a GitHub repository!

GitHub Deployment Tips

You can benefit from this feature in many methods, and here are some of the best tips on how for making use of it effectively:

  1. Manage your GitHub project using branches. only make changes to the primary in the event of merging branches.
  2. It is recommended to only enable the auto-deployment option if you follow the second recommendation.
  3. Test every aspect! Be sure to not let the issue get into the site of production.
  4. Take care with files you edit, most often you'll have to modify the WordPress-Contentor folder.

Summary

Git as well as GitHub are really effective tools for any developer available. It is now clear how you can use them to integrate together with WordPress.

It is possible to choose choosing either the SSH technique or the modern My features GitHub deployment. Each of them has its own advantages:

  1. The SSH method: Only works with themes and plugins. Make a repo by hand, build a theme or plugin and pull it from the server that your website is hosting on.
  2. GitHub Method of deployment: This is a innovative feature that is available for My. This is an automated process in which you can focus on the development of your website locally, while handling things like deployment.

Be sure to assess them for the most effective WordPress website you could.

How has the integration between WordPress with GitHub altered your website or your development process? Please share your thoughts in the comment section!

Article was posted on here