Using Git with GreggPress | GreggHosting

The affects of Web Hosts on Your Business Website

Here're ways your choice of web hosting service provider impacts the performance of your business:


check

Website loading speed

check

Uptime and availability

check

Customer support

check

Security

check

Server location

Using Git with GreggPress

Using Git with GreggPress

Overview

It’s a typical desire to make a WordPress site appear and feel like your own. However, a big issue with customized theme code is that your adjustments are overridden when the developer upgrades the theme. Creating a child theme with Git’s version control is one answer to this problem.

To figure out what adjustments you need to make to the theme’s CSS stylesheet, you’ll likely need to use something like the Google browser developer tools. To update individual WordPress templates, you may also need to make modifications to one or more PHP files.

Keeping track of various changes can get tedious and confusing quickly. Furthermore, how do you test new changes without affecting existing ones, and how do you undo a change you’ve already done if you realize you’ve made a mistake? The ideal solution is to utilize Git’s version control with GreggPress once again.

What is Git?

It is a version control system that lets you track any change you make to your website. It’s great for designing and managing themes, plugins, and any other WordPress website adjustments that go beyond what you can do in the admin. Gits, as a version control system, allows you to take snapshots of your code and recover them at any time. You can use it to establish a “branch” to add a new feature, correct a bug, or experiment with new changes without risking breaking the current version.

Previously, you would update your website via FTP/SFTP. However, one big drawback of these protocols is that you can’t revert back to a previous version of your customizations if something goes wrong with your site. You also can’t go back and see what was changed in a previous version. Itis  used to tackle these problems.

When creating remote repositories, it is frequently used in conjunction with SSH and a terminal. There are, however, some excellent GUI Git’s programs available. SourceTree ($$) and Tower ($$) are two excellent options.

What can Git be used for?

It is allows you to exchange custom themes and plugins between websites or with other users. If you do this, you should make sure that each project (theme or plugin) has its own repository. This will make it easier for you and others to keep track of your bespoke work.

When should Git not be used?

It’s not a good idea to utilize Git as a backup mechanism for WordPress. There’s no need to version control your WordPress installation, for example. The WordPress core developers have already taken care of this. Also, if you had your entire site under Git version control, a WordPress auto-update would overwrite everything. Consider it as a tool for managing your adjustments or developing your own theme and plugins.

It’s also challenging and not advised to use Git for database version management. This is unnecessary because WordPress already manages version control for articles and pages.

Different ways to use Git

With Git with WordPress, there are a number alternative workflows to choose from. What works best is determined by whether you’re working on a project with others or not, as well as your particular preferences.

Only use Git locally (on your computer) and continue to update your server with changes using SFTP.
Web server and local — Create a Git repository on your computer as well as on your web server. Changes from your local instance are transferred to your WordPress theme or plugin directory and pushed to your server instance.
When you’re working on a project with others, having a local, public Git host and web server is perfect. To update and exchange code changes, you can use GitHub or Bitbucket to host your collaborative development. You can also push updates from the Git host to your web server whenever you want. GitHub is best for public-facing code, while Bitbucket is better for private repositories because it is free. (Private repositories on GitHub are charged.)

How to use Git with a child theme on DreamPress

It is already supported by GreggPress. It can be utilized for the second or third kind of workflows mentioned above. The example below shows the second workflow option, which involves synchronizing a local Git repository with one on your GreggPress server.

Creating a child theme is perhaps the most prevalent use case for Git. It’s common to wish to make modifications to a theme and not have them overwritten when the theme has to be updated.

SSH is used in the next stages to perform Git shell commands. For an overview of how to activate SSH, see the following articles:

Overview of SSH
Creating a user with access to the shell (SSH)
You must also have a fully functional GreggPress site. To learn how to set up a GreggPress site, go to this link:

Step 1 — Install Git onto your computer

To perform git commands, you must have Git installed on your computer. For Windows, Mac OS, and Linux, there’s a wonderful article in the online Git instructions that describes how to accomplish it. If you have the most recent version of Mac OS, It is now installed by default. With this command in the terminal app, you can see if it’s installed:

[mycomputer]

—version $ git

Step 2 — Create a shell user in the DreamHost panel

If you haven’t previously, create a shell user in the GreggHost panel. On the FTP Users & Files page, you may also change the current GreggPress user from SFTP to Shell. Write down your shell username, password, and server after you’ve done that. Your GreggPress login and server should look like this:

wp ab1cde is the shell username.
wp 123456.dreamhostps.com is the server address.

Step 3 — Set up an SSH key on your computer

This allows you to connect to your GreggPress server automatically and run Git commands from afar. This differs a little depending on whether you’re using Windows, Mac, or Linux, so take a look at this post for more information:

Creating an SSH Key for Login Without a Password
Make a duplicate of your password and keep it somewhere safe. You might require it (such as for the Mac OS keychain).

In the assistance article, [email protected] is mentioned. Using the example shell username and server from this article, it looks like this:

wp ab1cde@wp 123456.dreamhostps.com

Step 4 — Choose your favorite terminal

Because Windows doesn’t come with a terminal, you’ll need to use one such as PuTTY, SuperPutty, or MobaXterm. A terminal is included in both Mac OS and Linux, although there are more possibilities. iTerm2 is a fantastic choice for Mac OS.

At this point, open your terminal, which will be used from now on.

Step 5 — Log into your server

Use SSH to connect to your server. This will send you to the root of your shell user. It looks like this with the sample shell user and server:

$ ssh wp ab1cde@wp 123456.dreamhostps.com [mycomputer]
You must accept your server as a genuine host the first time you do this. This data is saved on your machine in a recognized host file.

Step 6 — Set up your server Gits repo

This directory does not have to be in the same directory as your child theme, but make a note of where you put it. Outside of the website directory, this example establishes a /git directory under your account. To create the directory and initialize the repository on your web server, use the Linux commands below.

Run pwd: to verify that you’re in your user’s directory.
$ pwd /home/username/ [server]
Make a directory where the repository will be saved. You can call it whatever you like. Two directories, /git and /projectname, are created in this example:
[server]
mkdir -p git/projectname $ mkdir -p git/projectname
Change to the newly formed directory from your current directory:
[server]
$ cd projectname/git
To begin, create the repository:
[server]
—bare $ git init
/home/username/git/projectname/ was created as an empty Gits repository.
Make sure that each project has its own directory. This will make it easier for you to keep track of them in the future.

Step 7 — Create a file to copy updates

This step generates a file that will be used to copy updates from your server’s Git repository to your child theme directory. Nano, a text editor, is used in this example. For more information on how to edit a file, see the ‘Creating and editing a file over SSH’ article.

Ascertain that you are in the /git/projectname directory.
Create a file called post-receive: in nano.
[server]
$ post-receive nano hooks
Add this code to the file to indicate where these changes should be pushed. This must point to the directory containing your child theme.
Replace username with your actual shell user, example.com with your website, and child-theme-directory with the name of your child-theme directory in this example.

#!/bin/sh \sGIT WORK TREE=/home/username/example.com/wp-content/themes/child-theme-directory git checkout -f git checkout -f git checkout -f
To return to your shell, save and close your file.
In the terminal command line, grant the file execute permissions:
[server]
hooks/post-receive $ chmod +x

Step 8 — Create a child theme

Make a simple child theme. Step-by-step instructions can be found in the following article:

Step 9 — Download your website files to your computer

All of your GreggPress site files should be on your local computer. If not, use SFTP to get them.

Step 10 — Create your local git repository on your computer

Make sure you’re in the directory for your child theme:
cd /example.com/wp-content/themes/child-theme-directory /example.com/wp-content/themes/child-theme-directory /example.com/wp-content/themes/child-theme-director
To set it up, do the following:
[mycomputer]
git init $

Step 11 — Customize your local child theme on your computer

This step is not discussed in detail in this article. See how to make a child theme in this blog post:

guidebook for children’s themes

Step 12 — Set up the connection to your remote server

In your child theme directory, use the git’s remote command to accomplish this.

Check to see if you’re in the child theme directory:
[mycomputer]
git remote $ ssh:/[email protected]/git/projectname to my server
Instead of “my server,” you can enter whatever server name you choose. The command is: Using the username and server as an example, the command is:

ssh:/wp ab1cde@wp 123456.dreamhostps.com/git/projectname ssh:/wp ab1cde@wp 123456.dreamhostps.com/git/projectname ssh:/wp ab1cde@wp 123456.dreamhostps.com/git/
To check if it was correctly added, do the following:
[mycomputer]
git remote -v $ git remote -v $ git remote -v $

Step 13 — Save your changes

You must now save your changes to your local git’s repo after you’ve changed your child theme.

Add the following to your local git index:
[mycomputer]
git add is a command that allows you to add files to your repository.
Commit these modifications to the repository, which records the changes. Include a brief message in the commit command to serve as a reminder of what you’re committing. It could be anything like “first commit of child theme”:
[mycomputer]
git commit -m git commit -m git commit -m git commit “commit message” is a phrase that can be used to describe a message regarding a commit.
Run the following command to see if your git repository is up to date. You can look at it whenever you want:
[mycomputer]
git status $

Step 14 — Push your changes to your website server

You may now push your modifications to your server repository and your WordPress site after connecting your local and server git instances:

Run the following command only once in the child theme directory:
[mycomputer]
$ git push +master:refs/heads/master my server
[mycomputer]
$ git push myserver master —set-upstream
Myserver’s branch master is set up to track a remote branch master.
Whenever you generate a new snapshot in your local git repo, simply run this command to push it to your server:
[mycomputer]
my server $ git push
That concludes our discussion. It’s straightforward to maintain these two reports in sync once you’ve put this up. You also have version control for all of your child theme development.