Tag Archives: Git

Simplest GIT Server (over ssh)

If you should ever come to the need to have your own, personal git server and got shell access almost anywhere – here is how to set it up and use it.

Prerequisites

  • Shell access to a host on the net (this means you do have an user account with ssh login, ftp or the like will not suffice)
  • Optional extra: You are able to create a user to use with git (beforehand) – no need to do so, can be used with your normal user account though
  • Git installed on your machine and the remote, of course

Create a new remote repo

Log in to your (remote) host via ssh:

me@localhost:~$ ssh user@host

The following commands will create a directory called repos in your home dir and create a new git repo called name_of_repo.git there:

user@host:~$ mkdir repos
user@host:~$ cd repos
user@host:~/repos$ GIT_DIR=name_of_repo.git git init

That’s it!

Use it

Back on our local machine we want to clone that repo:

me@localhost:~/work/$ git clone user@host:~/repos/name_of_repo.git

If you already have data you want to put into your new remote repo you can do so as well, just add the new remote to your local git repo like that:

me@localhost:~/work/my_existing_local_git_repo/$ git remote add origin user@host:~/repos/name_of_repo.git

Last step is to push your local changes to the remote repo, as usual:

me@localhost:~/work/name_of_repo/$ git push origin master

And that is all there is to it!

Some extra stuff

Of course you can put your ssh public-key on the remote server, if you have not already done so, not to have to enter your password everytime you use git.

If you have created an extra git-repo user on your remote host, you can even give access to the repos to others by putting their ssh public-keys in the ~/.ssh/authorized_keys2 file.
WARNING: Be aware that they will have full shell access too, if you do not limit the according keys to only beeing able to use git! – Feel free to ask for details…