WPCloudDeploy includes the ability to push changes from servers back to your central (remote) repository. While this might sound strange, there are many instances where this can be quite useful.
However, as we illustrated in our Git Introduction section, using this ability can easily cause conflicts.
Still, sometimes the advantages outweigh the drawbacks.
One simple use-case is staging sites.
Many professional developers employ a DEV → STAGING → PRODUCTION workflow.
Once you are at the STAGING point of your workflow, it is typical that a lot of troubleshooting and changes might occur directly on the Staging server. In this case it would be quite useful to push those changes back to the repo (maybe on a different branch) instead of trying to manually copy them all back into the local DEV environment.
In this case, your process on a flow-chart might look something like this:
Another use-case is when running a WordPress SaaS. In this case most development of template sites will occur on a quasi-production server. Pushing and tracking those changes back up to a central (remote) repo is quite useful. And being able to quickly rollback to points in time or deploy different versions can be a lifesaver.
In git terms, two-way syncing is about using git init to create a local repository on the server for the site and linking that repository back up to your central (remote) one. To do this:
When the operation completes, the page will refresh and you’ll see a number of new sections:
We’ll discuss each option in their own sections below.
This just brings your site and the current branch up-to-date with the central (remote) repo. It does the following in order:
Notice that this operation is on the CURRENT branch. In the image above you can see the current branch (as we know it) is displayed in the green boxes.
This operation checks out a different branch from the central (remote) repo. All your site files will be switched to match the new branch.
This creates a new branch (using one of the existing branches as a base) and checks it out.
All subsequent changes to the files on the server will be applied to this new branch.
Using the SYNC option mentioned earlier will push changes to the new branch, not the original branch
A git tag can be thought of as a label. You’re able to navigate back to that label any time you want. In many cases it is used to label versions.
In WPCloudDeploy, when you create a new git tag, we automatically create a new folder with a copy of all the files in that tag. This folder is located here:
Tags created elsewhere (eg: on someone else’s machine or your local dev machine) will not have a versions folder unless you FETCH it (see the next section)
This operation will fetch the files for the tag from the central (remote) git repository and make a copy in the versions folder mentioned earlier.
This is useful if a tag was created elsewhere and WPCD knows nothing about it. This operation makes it aware of that new tag/version.
This option allows you to get a tag and then replace your site with files associated with that tag.
A few things to note about this:
This is probably not an operation that you want to use on a regular basis. BUT, it can be quite useful at times.
When attempting to initialize GIT for a site, it’s possible you might run into conflicts. If your REPO is the source of truth for you, then you can use the CLONE WITHOUT INIT button to copy all the repo files to the site first. Then retry the INITIALIZE GIT ON THIS SITE button.