Today I'll talk a practice that changed my life. Since when I work developing web applications I used to work with FTP to send files to server. Forget using FTP for that and welcome to the GIT world.

GIT became famous after the launch of GitHub website. GIT is a version control tool used to manage applications (or files) and control users files update and much more.

Basically you must have:

  • GIT installed on the remote machine and local machine
  • Repositories created on both machines
  • The files you want to deploy/upload

For now you'll use Ubuntu Linux on both machines to deploy our sample application. First we need to install GIT:

Remote Machine

  1. SSH your remote machine: ssh user@yourdomain_or_ip
  2. Install GIT on remote machine: sudo apt-get install git-core
  3. Go to path where you'll deploy files: cd /home/user/my_project
  4. Inside this folder create an empty GIT repository: git init

Local Machine

  1. Install GIT if not installed: sudo apt-get install git-core
  2. Go to your application path: cd /home/user/project
  3. Create an GIT repository with the files you already have: git init

Ok! We have both GIT repositories created. Assuming you have an application developed (local machine) you want to deploy, we have to add the files to the repository and deploy to the remote GIT repository:

Local Machine

  1. Add all new/updated files to the local repository: git add .
  2. Do your first commit to repository: git commit -m "first commit"
  3. Now we've to create a new branch (because your remote repository will not allow you to deploy to the master branch): git checkout -b devel
  4. Now we're inside 'devel' branch. So let's register where is our "remote server": git remote add origin user@domain_or_ip:/home/user/my_project
  5. And deploy files: git push origin devel

We have now all files deployed on the remote machine, BUT insite the "devel" branch of the created GIT repository. So we have to login on the remote machine and tell the GIT to MERGE the "master" branch with the "devel" branch (that we've deployed now).

Remote Machine

  • ssh user@domain_or_ip
  • cd /home/user/my_project
  • git merge devel

All right! Your files are all them inside the "master" branch on the remote GIT repository. Easy! Note that transfer files using GIT is faster than FTP and much more "professional".