Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Created November 9, 2023 21:21
Show Gist options
  • Select an option

  • Save jazzsequence/742b919850a9f2bb1f2b5267666dcd11 to your computer and use it in GitHub Desktop.

Select an option

Save jazzsequence/742b919850a9f2bb1f2b5267666dcd11 to your computer and use it in GitHub Desktop.

Revisions

  1. jazzsequence created this gist Nov 9, 2023.
    66 changes: 66 additions & 0 deletions update.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    When multiple WordPress versions have passed without updates being applied to your site, you will get a list of the updates in your Pantheon dashboard but no way to apply _specific_ updates to your site.

    <img width="889" alt="Screenshot 2023-11-09 at 12 58 26 PM" src="https://user-images.githubusercontent.com/991511/281853023-2c1f2017-71ce-4e1b-81d8-a71eb4f67d06.png">

    Generally, the only way to apply those updates is to click the Apply Updates button or use `terminus upstream:updates:apply`, but either of those options will give you _all_ the updates. What if you only wanted to update to a _specific_ WordPress version?

    That's what this guide is here to illustrate!

    ## Step 1: Add `pantheon-systems/WordPress` as a Git remote

    The first step is setting our upstream repository as a remote for your site. A Git remote is simply a place where your code lives. Typically, on a Pantheon site, you have a single remote, your Pantheon Git repository. By adding the `pantheon-systems/WordPress` repo as an alternate remote, it means you'll be able to directly pull the same changes down to your site that would get applied to your site when you apply updates. To do this, you'll run the following command:

    ```bash
    git remote add upstream [email protected]:pantheon-systems/WordPress.git
    ```

    Once that's done, you should be able to run this to validate that you have an `origin` remote (the default) and an `upstream` remote (the one you just added).

    ```bash
    git remote -v
    ```

    You should see two listings for `origin` (for `(push)` and `(fetch)`) and two more for `upstream`. The `origin` remotes will both point to your Pantheon Git repository and the `upstream` remotes will point to `[email protected]:pantheon-systems/WordPress`.

    ## Step 2: Get a list of available updates

    Using Terminus, we can get a list of all the available updates. While this is mostly telling us what we can already see in the dashboard, the thing that's most interesting about what the Terminus command gives us is the _commit hash_ of those updates.

    ```bash
    terminus upstream:updates:list <site>.<env>
    ```

    ![Screenshot 2023-11-09 at 2 00 26 PM](https://user-images.githubusercontent.com/991511/281867345-195bff48-597c-41c2-8b0f-c6d3222d1cdd.png)

    Pay attention to the Commit ID column, we'll need it later.

    ## Step 3: Pull from the `upstream` and set to your desired update commit

    This is where some Git magic comes in. You'll want to pull from your `upstream` remote, applying the incoming changes from those updates, and then you'll want to set your repository to your specific desired update. Let's break this down.

    ### Pull from the upstream.
    ```bash
    git pull -X theirs upstream master
    ```
    This step will pull all updates from the `upstream` remote repository. The `-X theirs` flag makes sure that we use the changes that are incoming in the case of any conflicts. This will actually bring you up to date with the latest update, but don't worry, we'll fix that in a second.

    ### Reset to the commit hash of the update you want to apply
    Remember I said to hang onto that Commit ID? Here's where it comes in. That ID is what's known as a "hash" and a Git hash is a marker to a specific commit. By using this hash, we will be able to reset the history to the _specific commit_ for the update you want to apply. We're going to do this by using `git reset`.

    ```bash
    git reset --hard <Commit ID>
    ```

    In this case the `<Commit ID>` refers to the ID or hash from the `terminus upstream:updates:list` command you ran earlier that references the specific update you want. Passing the `--hard` flag says to discard any changes that are from any commits that came _after_ the one that you're applying, which is what we want.

    ### Force push the result
    You'll want to push these changes up to your site now, and to make sure that you're pushing the right commit you might want to add `--force`. Technically, since the Pantheon remote won't be ahead of your changes (it never received those updates, after all, since you were only working locally) the `--force` probably isn't needed here, but sometimes when using `git reset`, Git will yell at you if you try to push and update that's actually behind the history, so I would just use it anyway.

    ```bash
    git push --force origin master
    ```

    ## That's it!
    At this point you should be able to go back to your dashboard and check for updates. The updates that appear should be the ones that would apply _after_ the update you just pushed to your site.

    Essentially, this process is just doing what Pantheon does behind the scenes when you apply updates since those WordPress updates are coming from `pantheon-systems/WordPress`. By hooking into that repository directly, you're able to have more control over what WordPress updates you are pushing to your site.