If you haven’t used Git before, it can feel overwhelming to implement and understand how you might use GitHub for WordPress. I’m confident that you will have a decent understanding of how to implement and operate Git in a WordPress project by the end of this article.

Let’s start by thinking of Git as a place to store code online. It also provides a way of adding to the code, accessing the code, and so on. It also maintains a thorough history of every change/commit made to the code base. Git is an extremely powerful development tool. It can be used to create parallel branches of code for testing new features. This allows experimental work without impacting the functioning version. Code changes can be implemented, tested, then reverted or thrown out if it isn’t working out. It allows code to exist in multiple locations while keeping all of them in sync. This is merely the tip of the iceberg. The rest requires a much deeper dive.

Most developers I know use Git from the command-line. If that is too foreign to you, there are some fantastic GUI systems available that can help achieve the goal. I’ll focus on the command-line here, but all the concepts apply the same to a GUI version.

Typically WordPress code lives two places: on the local development machine and the web server. Code and files can be updated via FTP or some other method. Using GitHub for WordPress, the code will exist in 3 places. There will be a local copy for development, a copy on your web server, and the master version in GitHub.

Step One

Go to https://github.com and get a GitHub account if you don’t have one. If you haven’t been following the news on this, it’s 100% free now. They even let you have private repositories at no cost. Thank you, Microsoft.

Step Two

Create a repository. Give it a unique name, and a description if you can. Also, you should mark it as private too. Once you complete this step, you will be provided a URL link to your repository. Copy the link, which we will use it in the next step.

Step Three

Connect the wp-content folder to the git repo directory we created in the previous step. Essentially, this step is informing our wp-content folder where to send data for storage and versioning. This is fairly simple if you have SSH access to your server. On your web server, use the following commands to get it done:

  1. cd ~/var/www/<your site>/wp-content
  2. sudo git init
  3. sudo git remote add origin <the link you copied in step two>

Step Four

Now we need to add the wp-content folder to our Git repository and upload the data. While we are still in the wp-content folder root, do the following:

  1. sudo git add .
  2. sudo git commit -m ‘init commit’
  3. sudo git push origin master

That’s it! Now you can access your code in the repository from anywhere. In order to copy the code locally, navigate to the root of your local WordPress project and remove the wp-content folder, then pull down the code. Use the following to do so:

  1. cd path/to/your/local/env/root
  2. rm -rf wp-content
  3. git clone <link to your repo> wp-content
Last modified: August 27, 2019

Author

Comments

Write a Reply or Comment

Your email address will not be published.