How to Integrate Github With Your WordPress Development

by on October 10, 2024
Cat silhouette with HTML code

Integrating GitHub into your WordPress development workflow can transform how you manage and collaborate on web-based projects. GitHub is powered by the Git version control system, which is a distributed system that tracks changes in source code over time, allowing multiple developers to work on the same project simultaneously without conflicts. This version control system addresses many challenges developers face when working on WordPress websites.

Without version control, tracking changes, managing updates, and rolling back problematic code can prove challenging. GitHub simplifies these processes, allowing you to maintain a stable and consistent codebase.

GitHub’s collaborative features, particularly its branching system, enable multiple developers to work on different aspects of a project simultaneously without interfering with each other’s work. This parallel development approach can significantly speed up your project timeline and improve overall code quality.

This guide walks you through setting up GitHub for your WordPress projects, covers which files you should include, outlines how to deploy your code, and reviews the best practices you should follow for success!

Why GitHub Is So Important for WordPress Developers

In addition to providing version control, GitHub transforms the development with process by providing collaboration tools and workflow automation that is perfect for WordPress theme and plugin creation.

A Sample Github Repo for WordPress Development
A Sample Github Repo for WordPress Development

Here’s how GitHub addresses common WordPress development challenges:

  • GitHub allows you to create branches for different features or bug fixes, easily compare versions, and merge changes, helping you experiment safely and recover from mistakes without compromising your main codebase.
  • Features like pull requests, code reviews, and issue tracking streamline teamwork, enabling effective communication and accountability.
  • The version control system encourages best practices such as regular code reviews, testing, and documentation, leading to higher-quality code and fewer bugs.
  • GitHub integrates with various development tools, including Continuous Integration and Continuous Delivery (CI/CD) platforms like Jenkins and CircleCI, project management tools like Jira and Asana, and code editors like VS Code and Atom, creating a smooth development process.
  • Being part of the GitHub community allows WordPress developers to participate in open-source projects, contribute to discussions, and network with peers.
  • GitHub provides robust security features like access control and audit logs, helping maintain codebase integrity and prevent unauthorized changes.

The Role of a Managed WordPress Hosting Provider in GitHub Integration

Managed WordPress hosting providers offer specialized environments optimized for WordPress development and deployment.

Example tools and features provided by hosting provides includes:

  • Staging environments for developers to test changes in a replica of the live site before deployment.
  • Automated backups to provide an additional layer of security, complementing GitHub’s version control.
  • Performance monitoring to identify and resolve issues that may arise from code changes.
  • Malware scanning and threat monitoring to protect your WordPress site from security vulnerabilities.
  • Expert support to assist with GitHub-related issues and optimize your development workflow.

Pressable recognizes the importance of this relationship, which is why our managed WordPress hosting platform integrates smoothly with GitHub.

Pressable's Integration With Github
Pressable’s Integration With Github

Setting up GitHub repositories with Pressable is straightforward through the dashboard, and code changes can be deployed directly from GitHub to the live site. There’s a complete guide in the knowledge base for how to get this up and running in your development workflow.

Files That Should Be Stored in Your GitHub Repository

A general rule of thumb is to only store the files you’re working on in your GitHub repos and nothing more – if you won’t touch it, it shouldn’t make the cut.

If you’re working on a WordPress-related project, this means your repo only holds the themes, plugins, or custom code you’re developing rather than the entire installation.

In general, you should never add your WordPress core files to your repo because of:

  • Security risks: Core files may contain sensitive information better managed by the WordPress development team.
  • Maintenance complexity: WordPress core is frequently updated. Including these files in your repository means manually updating them, increasing workload and potential for conflicts.
  • Redundancy: Core files are readily available through official WordPress channels. Including them in your repository is unnecessary and may lead to version mismatches.

Instead, focus on version-controlling your custom themes, plugins, and configurations, leaving core management to WordPress’s built-in update system.

You should also exclude static media files like images and videos to keep your repository small and manageable, and because version control systems struggle with binary files.

Consider using media management plugins or external storage solutions for your WordPress site’s media files, keeping your GitHub repository lean and focused on code. This way, you can also back up and recover media assets using tools designed to handle large volumes of data, simplifying the process in case of data loss.

When setting up the repository, you should create a .gitignore file, whose job is to tell GitHub not to track specific files and directories. By default, it should include your WordPress core files, your site’s wp-config.php file, cache files, and user-uploaded content like images and videos.

To use this feature, follow these steps:

  1. Create a file using your text editor and save it as .gitignore.
  2. Edit the file to include everything you want to ignore. For example, to ignore every PHP file, add *.php into the file. For WordPress, add the exact path from the root folder to whatever you want to ignore, e.g.,/wp-content to ignore everything in the wp-content folder.
  3. Upload the file to your GitHub repo.

Aside from the reasons outlined in the previous section, one more factor that should nudge you towards managed WordPress hosting providers is that they already understand what should and shouldn’t go in a WordPress development repository. As such, they will proactively take steps toward protecting your site. Pressable, for example, doesn’t pull WordPress core files or anything in the /wp-content/uploads folder.

Setting up a Development Workflow Between WordPress and GitHub

These instructions will focus on manual methods for configuring the workflow between WordPress and Github, but remember, it’s infinitely easier to go through a managed WordPress hosting provider.

Before moving forward, make sure you have Git downloaded and installed locally.

How To Push Files to a Github Repository from a Live Site

The first step in creating your WordPress-GitHub development workflow is pushing your site’s files and folders to the repo:

  1. Access your WordPress installation folder using SFTP or through your hosting control panel.
  2. Download the files you want to work on. Make sure you retain the proper paths for each one, whether it’s just one file or the entire site.
  3. Open the terminal on your device and run the command ssh-keygen to generate an SSH key for your device.
  4. Log into your GitHub account and go to Settings > SSH and GPG keys.
  5. Click on New SSH key and enter the key you just generated. This will allow your GitHub account to connect to your device.
    Adding an SSH key to GitHub
  6. Create a new repository and save it with your preferred name.
  7. From the …or create a new repository from the command line section, find the URL marked git remote and copy it.
  8. Go back to the folder with the items you want to push to GitHub and open a new terminal there.
  9. Run the command git init to initialize Git in the folder and treat it as a local repository.
  10. Run git add . to add everything in the folder to the local repository and prepare it for commits.
  11. Run git commit -m “[Your commit message here]”
  12. Run git remote add origin [The URL you copied in step 7 to link the local repo to the one on GitHub.
  13. Run git push -u origin master to push the code to the repo.

You can also use this process to push the files already in your local development environment to GitHub.

How To Deploy From GitHub to WordPress

Now comes the exciting part: deploying your code to your live WordPress site. You can automate the process using GitHub Actions, a built-in CI/CD platform.

You’ll need to create a new .yml file to set up the workflow that pulls code from the repo and adds it to the folder where you’ve installed WordPress via FTP. For GitHub to access your FTP server, you’ll provide the relevant credentials using secrets, which are private but shareable variables.

To speed up the process, this guide will use a prebuilt action whose repo is publicly available for you to audit if you have any concerns.

With that out of the way, here’s how to set up automatic deployment from GitHub to WordPress:

  1. Open your GitHub repo and go to Add file > Create new file.
  2. Enter .github/workflows/[Your_file_name.yml] into the text area that appears. Keep in mind, whenever you enter a forward slash, the interface automatically updates to indicate a new directory, as shown below.
    Creating a new workflow file in GitHub
  3. Paste the following code for the prebuilt action into the new file:
name: Deploy to WordPress
 on:
 push:
 branches:
 - main # or your production branch
 jobs:
 deploy:
 runs-on: ubuntu-latest
 steps:
 - uses: actions/checkout@v2

 - name: Deploy to WordPress
 uses: SamKirkland/FTP-Deploy-Action@4.0.0
 with:
 server: ${{ secrets.FTP_SERVER }}
 username: ${{ secrets.FTP_USERNAME }}
 password: ${{ secrets.FTP_PASSWORD }}
  • Go to the Settings tab in your GitHub repo, then Secrets and variables > Actions > New repository secret.
    Adding a new secret to a GitHub repository
  • Enter your FTP server in the Secret* text box, give it a name that makes it easily identifiable, and save.
  • Repeat this for the FTP username and password so you end up with three secrets, one for each.
  • Go back to the .yml workflow file and, under the server, username, and password, change the value to match using the format ${{ secrets.Your_secret_name }}
  • Commit and save the changes.
  • Perform the action when you’re ready to deploy the code to your site by going to the Actions tab, then finding it from the menu on the left, and clicking Run workflow.Running a workflow with GitHub Actions

General Best Practices for Setting Up Integration

Here’s a quick list of essential tips to guide you through the process. Don’t worry, it’s simpler than it sounds, so you can implement these best practices no matter your level of experience with GitHub.

Our recommended Github best practices include:

  • Branching strategies: Use separate branches (separate lines of development within a repository, like develop, staging, and main)  to isolate unstable code, enable parallel development, and facilitate easy rollbacks. This also prevents issues in one environment from affecting others and streamlines the development process.
  • Regular commits: Make frequent, small commits with clear messages. This practice enhances collaboration, simplifies debugging, and eases code reviews by providing a detailed, logical history of changes.
  • Clean commit history: Maintain an organized project history by carefully structuring and describing your commits. This creates a more coherent project timeline, making it easier to understand the evolution of features and track down issues when they arise.
  • CI/CD pipelines: Implement automated workflows with GitHub Actions for testing, building, and deploying. This reduces human error, ensures consistent quality checks, and accelerates development and release cycles.
  • Code reviews: Conduct thorough reviews via pull requests before merging. This improves code quality, catches bugs early, ensures standards compliance, and promotes knowledge sharing among team members.
  • Documentation: Keep README files and other docs current. This eases onboarding, minimizes misunderstandings, and serves as a reliable reference for project information, including setup, architecture, and APIs.
  • Security: Use GitHub’s security features like dependency and secret scanning. Regular automated and manual security checks help prevent vulnerabilities, protecting sensitive data and maintaining user trust.
  • Use specialized tools: The process can get quite complex, so you should consider looking into tools built to simplify things. For example, you could use GitHub Desktop instead of the terminal and Bedrock to speed up development with WordPress boilerplate code.

Pressable Is Here to Help

If you’re a WordPress developer looking for a reliable, hassle-free way to integrate GitHub with your website, Pressable has you covered. With our seamless integration, you can deploy to your sites from a repository, collaborate with ease, and maintain better version control.

Our features are specifically designed for developers like you, making it simple to streamline your development workflow. From automated deployments and staging environments to reliable security and expert support, Pressable has everything you need to take your WordPress projects to the next level.

When you’re ready to elevate your WordPress development process try Pressable and see how the right managed WordPress hosting can make all the difference!

Read More Articles in WordPress Tutorials

wordpress custom meta tags
WordPress Tutorials

How to Create Custom Meta Tags for a WordPress Website

Are you trying to create custom meta tags for a WordPress website? Custom meta tags are an essential part of an effective search engine optimization (SEO) strategy. Upon discovering them, search engines will use them […]

why switch from shopify to woocommerce
WordPress Tutorials

Why (and How) to Switch from Wix to WordPress

It’s really no secret that a website is essential for small businesses to establish their brand and connect with their customers. However, many small and medium-sized business owners aren’t skilled at things like web design […]

WordPress Tutorials

Why (and How) to Switch From Squarespace to WordPress

Are you thinking of switching to WordPress? According to research, WordPress currently powers 39.7% of all existing websites. It is also the largest CMS. There is a reason why so many sites use WordPress. And several […]