Working with local Git and remote

Hi everyone!

Today I will talk about Git. As I suppose you know very well, or at least, you know a little bid of what is it. Git is a code version control software. There are others like SVN, Mercurial… but today I will talk about working with Git locally and deploy your source changes into remote machines. If you need more information about Git, check wikipedia, always useful ;). Link

First of all you have to have Git installed, this guide is quite simple and help you to install GIT in any OS.

Once we have git, we can initialize our first repo.

git init
git add *
git commit -m "First commit with all my initial source"

Here we have the first step, and this could be enough if you’re not going to deploy your code outside your box.

For example, if you have your webserver and you want to deploy your local changes in the source, you may have to do something like this. Other reason could be to have a external backup. If your source is replicated in other box, the possibilities of loosing all your work decreases, everything fails, sooner than you think 😉

Remote repos

In this example I will deploy my changes to my Amazon AWS EC2 machine.

I connect throw SSH to the machine and type this commands:

mkdir -p /var/git/example
cd /var/git/example
git init --bare

Now what we have to do is add a remote repository to our local repo.

We go to your local repo directory and type:

git remote add aws
git push -u aws master

At this point, we have replicated our repo in the cloud ;D easy, isn’t it?

Now what we want to do is to deploy our repo into the working directory, for example the Apache2 directory. In our remote machine, we go to the working directory and type the following:

cd /var/www/workingDirectory
git clone /var/git/example .

At this time we create a copy of the repo, with master branch prepared to serve your pages!

Now any changes you push to AWS you’ll have to enter in your working directory and pull changes. Easy!

cd /var/www/workingDirectory
git pull origin master

First post of GIT, more tricks soon!

Stay in the cloud!

Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información.plugin cookies