Version control and Git are already familiar to many more experienced website builders, at least as a name. Utilizing them can also offer many significant benefits to the development of a WordPress site.
The article goes through what version control is, what Git and GitHub are, and why you should take advantage of them. At the end, you’ll also find instructions for creating your own GitHub repo for the files on your WordPress site.
WHAT IS VERSION CONTROL?
Version control means storing different versions of the same file, ie development stages, so that the content of the versions and the differences between them can be described using so-called metadata. Version control traditionally stores the following information: when and what changes were made to which file, and by whom those changes were made.
Version control is an important part of large-scale site projects, for example, where several people work at the same time. On the other hand, version control can also be useful in smaller projects. However, it is important to separate version control from the development environment and backups.
VERSION MANAGEMENT VS. DEVELOPMENT ENVIRONMENT
Version control is intended primarily for the overall development of the site. So they are not ideal for testing small changes or updates, for example. For this purpose, website development environments work much better.
Some of the hosting solutions for WordPress already include such a development environment. For example, in A2’s WP-Cloud service, each site has its own development environment, which can be used, for example, to test updates.
VERSION MANAGEMENT VS. BACKUP
With version control, it is possible to restore a single file or part of a site, for example, if it is found later that it is causing problems for the site.
Backups also allow you to restore your site to an earlier version, but it always requires you to restore your entire site. This means that any successful changes will also be replaced with the previous version.
Backups should not be used to develop sites, but only to restore the site in the event of a problem.
VERSION MANAGEMENT SYSTEM GIT
Git is a distributed version control system that was originally developed for version control of Linux development work. The development of the system was strongly influenced by UNIX tool thinking, i.e. in practice Git is a set of tools, each of which knows something well.
Git was developed in 2005 by Linus Torvalds and other Linux developers. Junio Hamano has been its main administrator since 2005.
Today, Git is widely used in both open source projects and the software industry. Its use can also be recommended for the development of WordPress sites – especially if there are several developers.
WHAT ARE THE BENEFITS OF GIT VERSION MANAGEMENT?
Git version control can be of significant benefit in website development. It helps both to work more efficiently and to monitor changes that change as a result of developments.
Thanks to version control, development work can be done in parallel and by several people at the same time. If necessary, the development work can be divided into separate smaller development paths (branch) and combined (merge) later. This allows you to work more efficiently when the whole project is not standing because of a single development path.
Git version control allows you to separate and combine different development paths.
Version control can also be used to restore a portion of an earlier version as needed in the event of a problem. Let’s take an example: a small change is made to a style file for a site and everything seems to work as it should at first. After a couple of weeks, however, you’ll notice that the change broke a less frequently used subpage. With version control, you can easily restore a style file to its pre-edit state without having to restore the entire site.
WORDPRESS SITE DEVELOPMENT USING VERSION CONTROL
Version control is also great for developing a WordPress site. In practice, version control is used to track all or desired changes to a site.
For a WordPress site, possible changes could include:
- publication or update of the article,
- installing or removing an add-on
- changes to the theme and
- various updates to themes or add-ons.
Version control can significantly speed up the development of a WordPress site, as the different parts of the site can only be worked on separately and merged. On the other hand, it also makes it possible to experiment with various changes at a lower threshold, when changes can be undone as needed without losing all the development work done.
Looking for Best web hosts, here’s the Reddit recommended web hosting List
WORDPRESS AND GIT
Git was not originally designed for WordPress, but also works great with WordPress. However, you should be careful that all the files you want are actually saved using Git.
Usually, Git only tracks changes to files, such as media files added to the site or the like. This information can therefore be stored in GitHub, for example.
Instead, content changes made to the site, such as new articles, pages, and subscriptions, are stored in a database that is not an actual file within the WordPress site. For this reason, you need to use some sort of separate method with WordPress, such as an add-on that allows you to save this information as a file. After that, that file can be saved in GitHub like other files.
DIFFERENT WAYS TO USE GIT
Git can be used with WordPress in slightly different ways depending on, for example, whether you are developing on your own or if you have more than one developer involved.
- Locally from your own computer – In this case, Git will only be used from your own computer and the changes will be updated from your own computer to the server environment of the WordPress site.
- Publicly on GitHub, locally on your own machine and in a server environment – This approach is ideal if you have multiple developers. Each developer can do development work on their own machine, after which the changes are exported to GitHub for integration and finally to the server environment of the WordPress site.
HOW TO USE GIT ON WORDPRESS?
Git is pre-installed on both a2’s web host and WP-Cloud. Users of other services should check with your wordpress hosting provider to see if Git is pre-installed. Below you will find instructions that will allow you to create your own repo in GitHub and copy the files from your own WordPress site there.
Please note that using Git requires a little more advanced skills.
1.Create an account on GitHub
First, you should sign up for GitHub if you don’t already have a Github account
Select sign up and fill in the required basic information.
Next, select the license you want and press continue.
In the next section, you should choose things related to your own experience and GitHub. Select the appropriate items and finally press submit.
Also, be sure to confirm your email address!
2. Create a new repo on GitHub
Repo in Finnish . Please note that a free account can only be used to create public repo.
3. Create an SSH key
Next, you need to create an SSH key, if you don’t already have one.
ssh-keygen cat /data/.ssh/id_rsa.pub
4. Export the data to GitHub
Copy the resulting text to the GitHub repository under Settings and Deploy keys.
- Title: Server Key
- Key: Copied text
- Select: Allow write access
This guide only gives the SSH key access to that repo, so if you want a so-called global key for all repos, you should follow the GitHub instructions.
5. Copy the site information to GitHub
cd /data/wordpress git init git add . git commit -m "Hello commit" git remote add origin URL git push origin main
Enter the following command to enable Git and copy your WordPress site files to GitHub.