Freelance writing


Content strategy

How to backup a WordPress site to Github

December 1, 2018

Another thing I used to think was impossible: backing up a WordPress site via Git.

This guide assumes you have set up your WordPress directory as a Git repo. It will only tell you the console commands required to create a backup.

To back up your WordPress site

  1. Navigate to the folder of your WordPress installation which is a Git repo. In my case, public_html:
    cd /var/www/html/sitename/public_html
  2. Type git add . to add all new files since the last update. You’ll see a lot of lines like this, which are all the new files being added:
  3. Prepare the new files and changes to existing files for backup by using the commit command:
    git commit -m "Message"
  4. Use the Message to describe the update, something like “Uploading new style sheets”
  5. Actually send the updated files to your backup with git push
  6. Enter the password for the account you’re backing up with, either Git, BitBucket or similar

It took me a while to get my head around this because I thought ‘git commit’ would upload the files, but you actually need the extra step of ‘git push’.

There you go!