To set up a GitHub repository for an existing WordPress site, you can follow these general steps:
- Create a new repository on GitHub and give it a name.
- On your local machine, create a new folder for your WordPress project.
- Initialize Git in the folder by running the command
git init
in the terminal. - Create a
.gitignore
file in the root of your WordPress project folder. You can do this by running the commandtouch .gitignore
. - Open the
.gitignore
file in a text editor and add the following lines to ignore the WordPress core files and directories:# Ignore WordPress core files
wp-admin/
wp-includes/
wp-config.php
# Ignore WordPress content directory
wp-content/uploads/
# Ignore log files *.log
- Save and close the
.gitignore
file. - Clone the repository: Once you have created the repository, you need to clone it onto your local machine. To do this, you can use Git, a command-line tool. Open a terminal window, navigate to the directory where you want to store your repository and run the following command:
git clone https://github.com/your-username/your-repository-name.git
- Move your WordPress files: Move all of the files from your WordPress site to the cloned repository directory. This will include all of the WordPress files and folders, such as wp-admin, wp-content, and wp-includes.
- Commit and push changes: Once you have moved your WordPress files to the repository directory, you need to commit them to the repository and push them to GitHub. To do this, run the following commands:
git add . git commit -m "Initial commit"
git push origin master
This will add all of the files in the repository directory to the staging area, commit them with a message, and push them to the master branch on GitHub. - Set up deployment: Finally, you need to set up deployment so that any changes made to the repository are automatically deployed to your WordPress site. You can use a tool like DeployBot or CodeShip to do this. Alternatively, you can manually deploy changes to your WordPress site by downloading the latest version of your repository from GitHub and uploading it to your site using an FTP client.
Overall, setting up a GitHub repository for an existing WordPress site requires some technical know-how, but it can be a useful way to manage and track changes to your site.
Workflow
Setting up a GitHub workflow on an existing WordPress site involves a few steps. Here’s a general overview of the process:
- Create a new GitHub repository: If you don’t already have a GitHub repository, you’ll need to create one. You can do this by logging into your GitHub account, clicking on the “+” icon in the top right corner, and selecting “New repository”. Give your repository a name and description, and choose whether you want it to be public or private.
- Install the GitHub Actions plugin: Install the GitHub Actions plugin on your WordPress site. This plugin allows you to trigger workflows in response to specific events, such as when a new commit is pushed to your GitHub repository.
- Create a workflow file: Create a new YAML file in your repository’s
.github/workflows
directory. This file will define the steps of your workflow, such as deploying changes to your site. Here’s an example workflow file:
name: Deploy to WordPress site
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy changes to WordPress site
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd /path/to/wordpress
git pull origin master
This workflow will trigger whenever a new commit is pushed to the “master” branch of your GitHub repository. It will then connect to your WordPress site via SSH and run a script to pull the latest changes from your repository.
- Configure secrets: In order to connect to your WordPress site via SSH, you’ll need to provide some sensitive information, such as your username and password. You can store these as encrypted secrets in your GitHub repository’s settings. To do this, go to your repository’s “Settings” page, click on “Secrets” in the left-hand menu, and add your secrets as key-value pairs.
- Test your workflow: Push some changes to your GitHub repository and make sure that your workflow runs successfully.