Thursday, January 8, 2015

SSH Server as the Git Repo

I have been using Dropbox as my private git repository. as discussed in HERE Similar to this, Google Drive can also be used as the git repository.

Problem

The problem is, when we are syncing the Dropbox (or Google Drive) in two machines, we are going to have Copy of Git Repo in two different machines. Even worse, if you decide to share the Repo with your friends, then the Repo is going to exist in multiple machines. Now imagine a situation, multiple users make a change to theie individual repo and sync at the same time. At such instance, when the Dropbox syncs, changes from one machine will be saved but others will be overriden.

So if you want to use Dropbox (or Google Drive) as SSH Repo server, then only one user can make change to the repo at a time. If another user (or machine) wants to make a change, he has to sync first and make sure that nobody else makes any change.

SSH - The Savior

It is also possible to use SSH server as the Git Repository. That way Git Repo will be located in only One Location and therefore we can efficiently use it as real Git Server.

All you have to do is create bare repository in the SSH server and clone in your local machine with the command:

$ git remote add origin ssh://user@host:1234/srv/git/example
This could be little different in MAC terminal though. In MAC terminal the URL will be different.
git remote add origin ssh://user@host/1234/srv/git/example
In SSH server:

  ~/documents $ mkdir test_repo.git
  ~/documents $ cd test_repo.git
  ~/documents/test_repo $ git init --bare
In Local Machine

  ~/documents $ mkdir source
  ~/documents $ cd source
  ~/documents/source $ git clone ssh://username@host:~/documents/test_repo.git







No comments:

Post a Comment