Overview
On your Windows home computer, you can place a website or application you have already created under git version control and use your DreamHost server as the 'remote' (external) repository you push to.
This lets you fully develop the website or application on your home computer while using your DreamHost server as an extra place to save your code.
How do I create an SSH key pair?
This step explains how to create an SSH key pair on your Windows computer. You must create SSH keys in order to interact with your DreamHost server.
- Download and install Git for Windows:
Select all default options during installation. For example, you should leave the radio button selected for Use Git from Git Bash only and all options for OpenSSL.
- From the start menu, locate the program you just installed. You're looking for Git Gui.
- Click the Help menu and select Show SSH Key.
- From the pop-up, click Generate Key on the top right.
You are prompted to enter a passphrase.
- Leave the input field empty and click OK twice.
Your public key is displayed.
- Click Copy To Clipboard.
- Open your start menu and open the program Notepad. Once opened, paste this public key.
- Save the file and name it something like dreamhost-git-key.pub. Make sure to save it in your Documents folder.
How do I upload the public key to my DreamHost server?
- Navigate to your Documents folder.
- Right-click and select Git Bash Here. This opens a terminal. Since you opened Git Bash inside the Documents folder, the terminal prompt should look like this:
user@computer MINGw64 ~/Documents $ - In the terminal, run the following command to ensure the dreamhost-git-key.pub you saved above is in this Documents directory.
[server]$ ls -la | grep dreamhost dreamhost-git-key.pub
The terminal outputs the name of the public key file you saved.
To run the following commands, you need the name of your DreamHost server and the user/password assigned to your website. View the following articles to locate this information:
Additionally, the DreamHost website username you're running the command with must be configured as a Shell user. View the following article on instructions on how to configure this:
- Run the following command to upload your public key to your DreamHost server (make sure to use your website's user and server name):
[local ~]$ cat ~/Documents/dreamhost-git-key.pub | ssh user@server.dreamhost.com "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
You may receive the following error when running this command:
mkdir: cannot create directory `/home/username/.ssh': File exists
This simply means the /.ssh directory already exists on the web server. If you see this, remove the portion of the command that creates the directory and run again. For example:
[local ~]$ cat ~/Documents/dreamhost-git-key.pub | ssh user@server.dreamhost.com "cat >> ~/.ssh/authorized_keys"
- Log into your DreamHost server via SSH:
[local ~]$ ssh user@server.dreamhost.com
- Confirm your key has been added to the DreamHost server by running the following (this should output your key):
[local ~]$ cat ~/.ssh/authorized_keys
How do I create a bare repository on my DreamHost server?
This step creates a bare repository on your DreamHost server. This will be the remote repository you push to from your local computer.
- Create a new directory for your new remote repository on your DreamHost server. If this code is meant to update your existing website, you should name it the same as your website ending in .git. For example, something like example.com.git.
Since this is a remote repository and not a working repository, the directory name you create must end with .git. You can then checkout this repository in the future to work on.
[server]$ cd ~ [server]$ mkdir example.com.git [server]$ cd ~/example.com.git [server]$ git init --bare [server]$ git symbolic-ref HEAD refs/heads/main
- Run ls -la to confirm the files and directories have been created.
[server]$ ls -la HEAD /branches config description /hooks /info /objects /refs
- Confirm the HEAD file is set to use main by running the following command.
[server]$ cat HEAD ref: refs/heads/main
You should see main being used.
How do I configure git on my computer?
- Navigate to your project folder.
- Right-click and select Git Bash Here.
This opens up a terminal that's already running Git.
- Run the following to create your user and email to be used with Git.
[local ~]$ git config --global user.name "John Doe" [local ~]$ git config --global user.email johndoe@example.com
- Run git --version on your local computer.
If your local git version is at least 2.28, run the following init.defaultBranch command to ensure all newly created repositories use the name main as the primary branch.
[local ~]$ git --version
[local ~]$ git config --global init.defaultBranch main
If for some reason you're unable to upgrade your version of git to at least 2.28, you can still manually change the primary branch name to main after you've made the first commit below. View the following article for further details:
The commands above create a .gitconfig file under your username. You can view it at: C:\Users\user\.gitconfig
How do I create my local git repository?
This step creates a git repository for your website on your home computer. You'll then use this to push its contents to your DreamHost server.
Run the following commands in your project directory to initialize the repository and create your first commit:
[local ~]$ git init [local ~]$ git add . [local ~]$ git commit -m "First Commit"
When you initialize the repository, a directory titled .git is created.
By default, you cannot see this in Windows. If you'd like to view hidden files (files that start with a period), click View in the top menu. To the right, check the Hidden items box.
You do not need to view this .git folder to proceed with these steps. This is just a way for you to see your commands have created the local repository.
How do I push my local repository to the remote repository?
This step pushes your local repository to your DreamHost server.
- Add the bare repository you created on your DreamHost server as a 'remote' within your local computer's git repository. Make sure to change user and server to your actual DreamHost username and servername.
The word dreamhost is just an alias. It can be named anything you want. But this alias name will be used when you push your content to your DreamHost server.
[local ~]$ git remote add dreamhost ssh://user@server.dreamhost.com/~/example.com.git
- Check that the new remote exists.
[local ~]$ git remote show dreamhost
- Push the local repository to your DreamHost server.
[local ~]$ git push -u dreamhost main
How do I confirm my repository was correctly pushed to my DreamHost server?
- Log into your DreamHost server via SSH.
- Navigate to the /example.com.git directory.
When you run git status in the /example.com.git directory, you'll receive the following error because this directory is not a 'working tree':
[server]$ git status fatal: This operation must be run in a work tree
- Clone the repo to a new location by running the following command. This allows you to view its contents:
[server]$ mkdir ~/cloned-example.com.git [server]$ cd ~/cloned-example.com.git [server]$ git clone ~/example.com.git ~/cloned-example.com.git [server]$ ls -la
This directory contains all the files you pushed from your local machine.
Using Git for web development
View the following article for instructions on how to push changes on your local computer to your live website.