How To Instal A Git Repo & Serve Via SSH

Love Git but don’t want to pay GitHub to have a private repo? No problem. Here’s the solution. I was looking for a way to create a repo and serve it on my server via ssh. Git made it really simple and we can do in 3 steps (copied from the [Reference 1]):

1. Create a repo

server $ mkdir ~/repos/
server $ cd ~/repos/
server $ GIT_DIR=project.git git init
server $ cd project.git
server $ git --bare update-server-info
server $ cp hooks/post-update.sample hooks/post-update

2. Clone it on the client side via SSH

client $ git clone user@server:~/repos/project.git # Check the [Reference 2]
client $ mkdir project
client $ cd project
client $ git init
client $ git remote add origin user@server:~/repos/project.git/

3. Code & Push

client $ touch README
client $ git add README
client $ git commit -m "Example."
client $ git push origin master


1. How to serve a Git repo via SSH:
2. How to map SSH identity files to SSH servers & usernames:

1 thought on “How To Instal A Git Repo & Serve Via SSH”

  1. It does not work.
    [client] $ git push origin master
    the above command gave me the following issue :
    error: src refspec master does not match any.
    error: failed to push some refs to ‘ssh://myname.server:~/repos/foo.git’
    need hepl !

Leave a Reply

Your email address will not be published. Required fields are marked *