Git is a common versioning tool. For a long time I preferred SVN on Windows, but git fully supports Windows SSH connections via putty/pageant. Here’s a quick introduction.

Git On Windows

Before Git and Pageant will work nicely together, you need to add a variable to your environment. You can do this using the following command:

set GIT_SSH=C:\Putty\plink.exe

On Your Local Windows Machine: Initialize Repo & Add Origin

Run the following commands to initialize a git repository and define a remote origin that we can push to whenever we want. Yes, you can do it the other way around using pulling from the local machine to the remote machine.


git init
git remote add origin ssh://root@IP:PORT/home/path/root/

Let’s take a quick look at the lines. Git init initializes the repo, then we define the origin using the ssh:// syntax. Don’t forget the port if you changed the SSH port! Followed by the path your git repository on the remote machine.

On Your Remote Machine: Initialize, Add And Commit

On the remote machine, we do it in a similar way. First we initialize a repo (doesn’t matter whether you have already files there, you can turn an existing site into a fully git-compatible repo)


git init
git add .
git commit -m 'message'

Using the “add .” command we add the entire content of the directory. However, it may be more practical to only add certain folders e.g. wp-content like this:


git add wp-content

Finally we commit the whole thing and add a message.

Final Step: On Local Pull From Origin (Master Branch)

Branching is a basic concept of git that allows you to create a sub repository for changes to your code so we don’t modify the core. You can also protect the core/master.

Alrighty, now lets pull a copy so we can work locally:

git pull origin master

Now it should download a proper copy. If it says “fatal could not read from remote repository” make sure you entered the path correctly. Most often this error occurs when you are entering an incorrect path or forgot to add your SSH key to your pageant instance.

Questions?

This is a basic, rudimentary rundown that should help you getting started with Git on Windows using Putty.

Here are some additional resources I found useful: