Github explanation and guide to using it for WordPress developers

WordPress developers can rely on a set of software tools and technologies that help them create their own WordPress themes or plugins, or even develop previous templates and code. 

Among the most famous of these tools that are indispensable for any developer is the Github platform, which helps programmers and developers in general, and WordPress developers in particular, manage software project versions, share their files, update them, and upload them upon request. 

If you are not using Github in the development process, do not worry. In today’s article, we will take you step by step to explain Github, teach you how to benefit from it, and show its uses for WordPress developers.


What is Github? 

Github is a platform or web service that uses the Git system to primarily manage versions of software projects. It facilitates the sharing of software projects among a group of developers. 

The main use of Github is version control, which means that while developing a software project or a WordPress site, for example, you can develop the file locally (in a local repository), then synchronize the project with a remote repository (repository on Github) and upload the project files. on him.

Now, every time you make modifications to your project in the local repository you can publish them to the remote repository. You can also go back to any previous stage of project or site development and retrieve it before publishing the recent modifications. 

So you need to create a repository for each project you work on, so that the complete source code of your project is stored in this repository. There are two types of repositories: the local repository that is created on each developer’s computer.

The remote repository (shared repository) is the main repository that all project developers share and obtain the latest information from by pulling it from the remote repository to the local repository.

There are two types of local repositories: an empty repository whose files you create yourself, or a replicated repository that you bring to your local computer from a remote repository. You can create a copy of the remote repository on your personal computer within the local repository.

All change logs are then copied to the local repository so you can remain in your local environment and act as if you were connected to the server containing the remote repository.
You can make the contents of your project’s remote repository public and accessible to everyone. Or make it private if you want to keep its contents private and not be shared with others.

The platform also allows users to explore and share open software projects for other developers, and view their source code. They can also download open projects from the platform to their devices and modify them or rely on them with the aim of building a new software project. 

What is Git and what is the difference between it and Github?

Git is a version control system. Instead of storing a complete copy of any version of each file, Git only stores the differences between each version. GitHub is a hosting site and social network built on Git.

You may get some confusion when dealing with Git and Github, as they are not the same thing. As we mentioned, GitHub is a web service that uses Git, which is considered one of the version control systems to manage changes and updates to the software source. It was originally used by the Linux development team and is now used in developing software projects.

To use Git, you must install a command line program (or what is known as a terminal) on your local machine, through which you can write commands related to connecting to Github, copying, uploading, and controlling projects. 

As for GitHub, it is a service or web platform that uses Git and can be used by individuals and companies, and its purpose is to facilitate the use of the Git service. 

note: 

There are other alternative services that use Git, such as Bitbucket and GitLab, but the GitHub.com platform is the most famous, so we will devote this article to explaining them.   

How do I use Github?  

1 – To start using Github, you first need to create your own account on the Github platform  to create the remote repository that you will link with the local repository, as we will see in the following paragraphs.

Go to the main page of the platform, press the Sign up button and fill out the personal data as shown in the following image to create your own free account.

GitHub is just a host for the project, so all the actual development happens on your local machine. Then it is lifted to the platform.

2- You must then install the Git terminal on your local device, and if you are using the Windows operating system, you can obtain it from the following link , then click on Download for Windows to install it on your device. The Git program will appear as a command line as follows: 

From now on, we will use this terminal a lot to write various Git commands that will mainly help in managing the WordPress project on the Github platform.

Note:
Instead of the Git command line terminal, you can use the GitHub Desktop GUI client on your local machine to communicate with GitHub through it, but it is better to learn the basic Git commands first. 

How can a WordPress developer benefit from Github? 

The Github platform helps WordPress developers and users alike in different aspects and fields, and in this paragraph we will mention to you the most prominent benefits.

First, you can use Github as a free hosting service in order to save the WordPress project you are working on and the ability to share and make this project available among several parties so that other users can contribute to it and download it.

Where the developer can invite other people to contribute to the WordPress project and develop it as well, and then upload the changes and additions that were added to the project by others, to his local project.

A developer can also use Github to manage versions of his project. A WordPress developer can create his own repository on Github, and then transfer the content of the files of the software project he is working on (such as a WordPress template, or a WordPress plugin that he is developing). 

Then he can start developing the project locally (Localhost), and every time he makes radical changes to his project, he can send these changes to the repository in Github and save them in the remote repository. 

This helps the developer keep his software project hosted online, so that it can be accessed from any device, and make modifications and developments to this project at any time and from any device. 

You can also rely on Github as a source to restore the WordPress project to a previous state, in the event that the project implementation fails after many modifications. For example, if you, as a developer, make radical modifications that make the project unusable, you do not need to create a new project and start from scratch. Rather, you can return to one of the previous versions and restore your project to a state in which it was working well. These are the best uses for version control in Github.  

GitHub is also a rich source for hosting plugins or themes that you can download by going to the main page of the plugin or theme repository on GitHub. And click Clone or Download button, then click Download Zip button. Then you can upload the add-on or template to your site in the usual way. 

However, although there are many distinctive WordPress projects on GitHub, you must be careful about these projects and verify them before using them on an actual website, as they are ultimately projects presented by individuals and not from official sources. 

Another use for Github is to synchronize changes on the content side and not just the code side. For example, you may want to allow posts to be edited by multiple users who are not necessarily registered with your WordPress blog. Here Github helps you sync your blog content.

To do this, you need to use a dedicated WordPress plugin such as WordPress GitHub Sync,  which allows content publishers to edit posts collaboratively, revealing who made any changes to the content and when they were made. It can also allow readers to submit suggested improvements to the content of your blog or WordPress site via a special GitHub form. 

Essential terms and concepts to know about Github

Before continuing further and delving into how to create and host projects on Github, you must know a set of terms related to the Github platform before dealing with its practical use. 

  • Repository:
    It is the place or container in which something is stored; Here we create a Git repository to store all the project files for your project, and store all the project details such as the description and the programming techniques used. In addition to other characteristics, such as the number of contributors to the project, the number of stars, and other information.
  • Commit:
    When you make a change to a file or group of files. You want to confirm and save the change through a process called Commit. Git creates a unique ID that allows you to keep a record of the specific changes that were made, identifying who made them and when they were made.
    This instruction usually contains a message that briefly describes the changes made to the project, as follows: 
git commit -m “the reason for the change”
  • Clone:
    ​​which is creating a copy of the remote repository on GitHub on your computer to begin developing it. In other words, it is the process of downloading the project, as this can be done using Git commands, or manually via the upload button. 
    When you create a copy, you can edit the files and use Git to track your changes without having to be connected to the Internet. The repository you copied locally will remain connected to the remote repository so that at any time you can push your changes from the local repository to the remote repository. 
  • Push:
    means sending updates and changes that have been installed or committed to the remote repository on GitHub.
    If you change something on your local machine, you then have to push or send those changes to the remote repository so other developers can access and share them.
  • Pull:
    Pull lets others know what changes have been pushed or submitted by a project developer to the main GitHub repository. Once the pull request is made, the set of new changes and modifications made in the primary repository can be obtained.

    This is useful when more than one developer is working on a project at the same time, as you can pull the modifications they made from the main repository to your current repository. 
  • Branch:
    A project can be divided into more than one branch. A branch is a temporary workspace located within the repository to which changes can be made without affecting the main branch or the basic version of the project.
    Then you can finally merge these changes into the main branch of the project. You can then delete the branch after merging its changes from the master branch because its purpose has expired.
  • Fork
    A fork is a personal copy of another user’s repository located on your account. It allows you to make the changes you want to the project without affecting the original repository. You can also make a pull request on the source repository and keep the fork in sync with the latest changes in that repository since both repositories remain connected to each other.
  • Merge: 
    Merge is a process that takes changes from a branch or a fork and applies them to another branch. The merging process is performed through a pull instruction or request executed through the GitHub platform or through the Git command line terminal.
  • git branch command:
  • It comes with a set of different commands related to branches. Such as creating a new branch, deleting a specific branch, or viewing all branches in the project. 
  • git checkout command:
  • It is the command that allows you to transfer between branches, and move from the main branch to the secondary branch or vice versa. 
  • git merge command:
  • A custom command to merge all the changes added in the branches to the last main project to form a single project that includes all the modifications. 

Note: You must ensure that there are no conflicts between branches before you can merge them. Merge conflicts may occur when, for example, people make different changes to the same line of the same file, or when someone edits a file and another person deletes that file, for example. 

Through the following link , you can obtain comprehensive documentation that provides you with all the instructions you want to know about the GitHub platform. 

How to create a repository on Github and upload a WordPress project to it 

In order to start using Github as a project management system for your WordPress project, you first need to create a repository on the Github platform. Go to the Github website and then create your own account on the platform as we explained before.  

Then, go to the home page of your Github account, go to the top menu, and click on the New Repository option: 

Another page will appear asking you to include information about the warehouse, which is as follows with its explanation: 

  1. It is the repository name option, and it is preferable to name it with a name that expresses the project. If your project is a WordPress template, give it the name you chose for your template, and if it is a WordPress plugin, give it the name of your own plugin. 
  2. Description of the repository and information about it, which is optional. You can leave it blank if you wish. 
  3. It is a choice whether the project is open for everyone to view, private for viewing alone, or allocated to those who are invited to the project. (Not long ago this was a paid option, before Microsoft acquired Github and made it available for free.) 
  4. It includes multiple project-specific options, such as adding a Readme file that includes an explanation and documentation of the project, and a gitignore file to which we add files that we do not want to upload to the main repository. 

After selecting all the options, create your repository on Github. Once you create your repository, you will get an Https/SSh link that you can use to copy the remote repository to your local machine as we will see in a later paragraph. 

A set of options for uploading your own project to the repository will also appear. The instructions page will be distributed into groups as shown in the following image: 

Now we need to create a new local repository on the command line and link it to this remote repository. We will create the local repository on disk D under a folder named Demo, to do this we need the first set of instructions. So open the GIT terminal program that you downloaded in the previous steps on your computer and type the following instructions in it.

$ cd d:
$ mkdir Demo
$ cd Demo
$ git heat

This will create an empty repository on your local machine 

You can also go directly to the place where you want to create the local repository on the computer, then right-click in this location and choose Git Bash Here in order to open the Git command line directly in this location, and enter the git init command directly.

Now you have to link and synchronize the main and local repository with each other through the following command. To connect your computer to GitHub, use the following command:

$ git remote add origin https://github.com/TEAlearn/demo.git
$ git remote add origin https://github.com/<your_username>/Demo.git

Now we have connected our local copy of the repository to the remote repository on GitHub.com. 

Then write the following instruction: 

git branch -M main

This instruction is for transferring to the main branch. If there are other branches, you will be able to transfer to them via the same command by changing main to the name of the desired branch. 

Finally, write the following instruction: 

git push -u origin main

This instruction is the push instruction that will send the complete project files to the remote repository. 

(When you type this command in the Git terminal, the system will ask you to register with your Github account, and when the connection is successful, the required files will be uploaded to the remote repository.) 

To make sure, go to your account on the Github platform and review the repository and make sure that the new file is there. 

In the same way, you can create and upload all project files to the remote repository, then go to the repository link you created, and congratulations, you have now successfully synchronized your project with Github. 

How to avoid uploading some files to Github? 

You may not need to upload all the project files to WordPress, so there is the .gitignore file that we mentioned while creating a repository on Github. This file includes a set of settings as follows: 

Inside this file, you can add the name of any folder or file that you don’t want to be uploaded to Github. In the following example, we avoided uploading the node_modules folder, which is a folder containing very large files that are installed in order to run the project, and it is not necessary to upload them to Github. 

How to upload a WordPress project from Github to your local machine

Github allows for the opposite process of uploading from a local repository to another repository, which is the process of withdrawing or downloading the projects available on the platform to your own device for modification. Whether you are invited to work on a WordPress project, or you find one of the open source projects, you can withdraw it and use it to your advantage. 

Select the project you want to download to your device, then go to its repository link. In the drop-down list of the Project Code button, copy the link to this project as shown in the following image:

Then choose where to copy your project on your computer. Choose any folder on your local machine, then right-click again in this location, and choose Git Bash Here to open the Git command line, and then enter the command git clone followed by the project link, as follows: 

After completion, you will find the project folder has been copied to your device. You can now start modifying it normally, just as you would modify any project files.

With this, we have reached the end of our article in which we explained the most important commands that you need to use while dealing with WordPress project management using the Github platform. All you have to do is start trying it and use it in your work as needed. You can also view more important explanations and instructions through the official reference .

Avatar photo
I am a young man who has been working in WordPress and e-marketing for 10 years. I would like to share my experience with you so that we can become professional in WordPress I will be happy to share the experience with you.