Sync your job accross multiple computers with git

Written by
Date: 2012-02-26 11:47:00 00:00

As some of you already know, this blog is generated by jekyll, wich I run directly on my Linode VPS. I ssh my server, use vim to write my posts, and then generate the blog with jekyll, but sometimes I want to write while not connected, I use rsync to backup my entire blog to my Macbook Pro, and to my Arch Linux Desktop.

Today I studied a little about git, and read some manuals, and after learning a little about it, I have seen that it could be a good option to keep my blog in sync with the three computers I have: My server, my Desktop and my laptop.

What I have done is:

  1. Created the git repository in the server
  2. Cloned the repository to the Desktop, laptop and the server itself.

Now I have the same info everywhere, with a version control, (yes rsync can do that too, but I like to learn new things)

Here is how I finally did it.

I will assume you have already know how to install git in your current operating system

  1. Create the Master Repository in the Server

I have done this in my main server (the VPS) which is powered by Gentoo.

mkdir ~/my-git-master
cd my-git-master
git -bare init

Now the repository is created.

  1. Clone the repo, in the same machine, in case I would like to work via ssh

    mkdir ~/my-synced-folder cd ~/my-synced-folder git clone ~/my-git-master

  2. Clone the repo, in the remote computer.

    mkdir ~/my-synced-folder cd ~/my-synced-folder git clone ssh://user@gentoo.server/~/my-git-master

OK, now I just only need to add some content to any of sides, let's say the remote computer

cd ~/my-synced-folder/my-git-master
echo "This is a test" > test.txt
git add -A
git commit -a

Add your comment in the file that will automatically be opened.

git push origin master

Now, when you want to continue your work in the other computer.

cd ~/my-synced-folder/my-git-master
git pull

Et voila!, you know have the same content in both computers, and you can have a third or fourth, just remember that whenever you change something, you need to run:

git add -A
git commit -a
git push origin master

And on the computer you want to star working later, always run, before starting:

git pull

This is not intended to be a complete guide, just a guide, for you to start working with git.