Loading...

Jammie Mountz

Software Engineer

Use Github to deploy, backup, and update your website

Using Github to manage your website means you’ll have versions of the site live, locally, and on GitHub. I figured this would be a good way to easily keep backups of my site, and work on code without FTP.

What you need:
Paid Github account (for a private repository)
Git installed on your computer
SSH enabled hosting

If you’re working from a site you already have made, you should download the entire site locally if you haven’t already. You can do that by connecting to FTP and finding your site – usually located in /var/www. Download it into a local workspace.

On the Github site, make a private repository. Name it something corresponding to your website.

Hook your local version of the site to GitHub
In the terminal, navigate to the local folder containing your website. Once inside the directory, initialize the github repository.

$ git init

Move through the steps needed to commit.

$ git add .
$ git commit -m "Pushing site"

Connect the repository to the one you made online – replacing the URL with the one given to you on the site.

$ git remote add origin https://github.com/username/repository

You can check that its connected to the remote repository by entering:

$ git remote -v

Time to push to GitHub.com.

$ git push origin master

Logging into Github, you’ll see the site under the repository you defined.

Deploy the Github Repository on your server
Navigate to /var/www/ on your remote server through ssh and the terminal – we’re going to clone a copy of our repository into this location.

$ cd /var/www/
$ git clone https://github.com/username/repository

Make sure it’s named the same as your website directory – if not, you need to update the Apache sites-available document to recognize the newly named directory. Restart Apache if you change any config files.

$ sudo service apache2 restart

You’re connected!
You can work locally on the files, push it to Github, and then pull it to your remote server hosting your site. Navigate to your remote site and pull the most recent version off of Github –

$ git pull origin master

Leave a Comment


Fluent in Spanish and JavaScript, salsa dancer, lover of material design.

Living in San Francisco, CA