How to use Git with InstantWP

If you are using the amazing free InstantWP WordPress development package often, then you might start wondering how to properly use it with Git version control. The difficulty is that trying to add the entire Linux Alpine virtual operating system to Git is too heavy, but adding only the contents of the Theme folder will not keep track of your posts and other database related content. I will outline the steps I used to get Git working with IWP below:

The strategy I ended up using was to install Git to the Linux Alpine machine via the SSH terminal that is provided with IWP.

Here are the steps:

Type these commands into the terminal window (which you can open from the IWP panel):

sudo apk update
sudo apk add git

That should make sure you have Git available. The next step is to change your working directory to a directory that contains all the data that makes your WordPress site work (so both the database files and the WordPress installation). The folder is called “var” and you can find it at the root of your file system. You might need to use cd .. a few times to move up in the hierarchy. You can check the working directory you are in with “pwd” and the contents of the folder you are currently in with “ls”. You might have to elevate yourself to root user with sudo -s and the type in cd /var/. If you can see “var” in the list, then cd into it with cd var. You can cd into localhost even if it’s not listed with cd localhost. You shouldn’t need to change folder permissions here, but if you need to do that in some other situation, you can use chmod like in this example we are giving a folder called wp2 full permissions: chmod 777 wp2.

Next we will initialize the var folder as a git repository by entering

sudo git init /var

That should make a .git folder appear inside the var folder. Then we’ll add all the files in the var folder to our repository with

sudo git add .

That step will take a while. After it’s finished, we can make our first commit like this

sudo git commit “first commit”

If you want to push your commit online, you will of course need to have a repository created at Github (or some other host). So if you don’t, go there now and create a new repository. Then you can push to that repo with

sudo git remote add origin
sudo git push -u origin master

Provide your Github username and password when prompted.

When you do later commits, you might end up in a situation in which the terminal says

Please enter the commit message for your changes. Lines starting
with '#' will be ignored, and an empty message aborts the commit.

You will now simply need to type in a commit message at the top line. Here are the steps for doing just that:

 -type i in order to start writing

-When ready, hit esc to go back to command mode

-Save changes by typing :w and hitting enter

-Quit with :q and enter and it will bring you back to the main console.

Or you can use the -m flag and avoid having to do the edits above. Use the flag like this

git commit -m "your message".

Later when you continue working, just perform these steps:

Launch IWP

Open up the SSH terminal and start typing git commands. For example

git status

will give you the latest status of your repository (so you can see if there are any changes that you need to pull)

Leave a Reply

Your email address will not be published. Required fields are marked *