Tag Archives: git

Deploying static websites to VPS using git

git is a distributed open source version control system. If you’re not already familiar with git then read some free tutorials listed here and come back after you have some basic understanding to follow through the tutorial. Whether it’s a static website or a fun project, it’s usually a good idea to use a version control system such as git. Additionally, git can also help you in deployment and make your development workflow much easier and simpler.

git deployment

Step #1. Server Setup

If you’ve not already selected a VPS then get one there on Digital Ocean or Linode. Make sure you select Ubuntu (preferably : 14.04 LTS) for the server OS. Otherwise, you may need to adjust few commands depending on the Linux distribution you’re using.

Step #2. Configure git on the server

SSH into the remote server and configure git for deployment.

ssh example_user@IP_ADDRESS
mkdir example.git
cd example.git
git init --bare

Next, create a git hook – a shell script that will be executed on git push (to update code on server).

nano ~/example.git/hooks/post-receive

Here is a sample post-receive script you can use : (use Ctrl+X to save and exit)

And make it executable.

chmod +x ~/example.git/hooks/post-receive

Step #3. Install and configure git on dev machine

First, install git, move into your project directory and commit it under git.

sudo apt-get -y install git-core
cd example.com
git init
git add .
git commit -am "MVP is ready for the wild"

Add remote repository for deployment server.

git remote add production ssh://example_user@IP_ADDRESS/~/example.git

And now, you’re ready to deploy. Just type (to push recent changes to live server) :

git push production master

Step #4. Configure nginx

ssh into the server and create a nginx config for the domain (example.com).

sudo nano /etc/nginx/sites-available/example.conf

Here is a sample config you could use :

sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/example.com
sudo service nginx reload

Now, update the DNS settings at the registrar and create two records – one for naked domain (e.g example.com) and other for www-version of the website (e.g www.example.com) – both pointing to the server IP. And, wait for the DNS to be propagated (few minutes).


want to Learn git ? Start Here!

What is Git ?

git is a distributed version control system, developed by Linux Torvalds during the development/management of Linux Kernel. In other words, it’s a software, a tool, that simply keeps track of the different version of the files, If you mess up, you can easily go back to some previous (correct) version of the file. (to any commits)

The purpose of the version control system is to maintain the consistency between the changes made by different(or may just one) people on a large complex project, it allows them to contribute simultaneously in an easy way. Being distributed means – everyone has the full copy of everything – and everyone can work independently (even without any internet connection, but in case if they want to share the changes with other remote developer, the connection will be required as usual).


Why use a version control system such as git ?

There are many advantages such as –

  • it keeps tracks of different versions of the files in your project
  • it’s very fast
  • it also works as a backup for all your files/changes
  • it’s easy to manage the project if there are more than one people working on it
  • a number of people are already using it, so if you want to collaborate on popular open source project or in an organization then probably you might need it
  • it’s distributed and you got full copy of project files, so you can work offline
  • there are cool project hosting apps such as github that makes git even more fun

How to Learn Git ?

First of all, learn some basics from any sources, and start using it in your project. You can’t just learn git by watching videos or reading manuals – you must use it. It’s a very practical thing, even if you learn all the basics of git – you will eventually forget it unless you apply it somewhere.

Recommended tutorials to begin with git :

Note : All the above tutorials are free but if you don’t mind paying for great tutorials then you must checkout “git real” course on Code School.

update 1: added codeschool link!
update 2: added link to some new tutorials!
update 3: added a link to visual explanation for git

Try Git

Getting Started with Git using “Try Git”

Git is the most popular version control system, developed by Linus Torvalds (yeah!, he is the same guy – Creator of Linux) – for maintaining linux kernel code but now adopted by most of the developers.

Git is a distributed, fast, and efficient version control system (and of course – it’s a free and open source software), and most importantly –  it’s easy to learn. So if you’re new to version control system and need one for your next project then better start with git.

New to git ? Try Git in Your Browser (No Setup required)

Try Git is a simple web application that will explain some basics of git, in a very interactive way (just like try ruby). Since it’s browser based app so you don’t need to setup anything –  a modern web browser (such as Firefox, Chrome .. but not I.E) is enough. So in very short time – you can easily get an overview of git, it’s features and how it works (it simulates a git environment and allow you to execute git commands in browser).Try Git

It has been developed by Github (Social Coding – like a Facebook for Developers) and Envylabs (company behind codeschool and TryRuby).

Try Git – Learning git in 15 minutes

Recommended Links for Learning more about Git

gitk snapshot

How to install Git on ubuntu 11.10/12.04

Git – is the fast, simple and easy to use version control system, and of course it’s a free software! Git is basically a distributed version control system (unlike subversion, which is a Centralized one) and you can even work offline, because network access is required only when you want to sync project files (using push, pull or fetch command). If you are new to version control system, then you must give it a try, it will make your development work less painful.

Ubuntu has now become a popular choice for development platform, so if you’re new to Ubuntu, then in this article you will learn how to start using git on Ubuntu 11.10/12.04/or older versions.

gitk snapshot

Install Git from Official Package Repository

it’s the most easy and recommended way to install Git on Ubuntu, but sometimes you may not get the latest version from the package repository, so unless you have strict version requirements/dependencies go for this method.

open a terminal and execute –

sudo apt-get install git-core

After installing Git, you may like to install gitk for visualizing commits in graphical way.

 sudo apt-get install gitk

Installing Git from Source

If you install git from source, you will always get the latest version. You may have to install some dependencies such as curl, zlib etc before installation procedure.

Install dependencies

sudo apt-get install  devl expat openssl zlib1g zlib1g-dev

Download the latest source code from the official site, and extract it. Then execute the commands (from the directory) –

make prefix=/usr all
sudo make prefix=/usr install

That’s All, now you can start using git for your project. e.g

cd your_project_directory
git init
git add .
git commit -m "It's my first commit"

Recommended Reading(s)

  • gitref.org – A good Reference/Tutorial for git
  • Intro to Git – Good introduction to Git, available in Video and PDF formats