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 contents of the folder you are currently in with “ls”. If you can see “var” in the list, then cd into it with cd var.

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 https://github.com/myUserName/myNewRepo.git
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".

Leave a Reply

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