Create a new self-hosted git repository

08 Aug 2013

You have access to a server already running git, and you want to use it to store a private remote repository.

You might want to make sure to have set up passwordless ssh beforehand. Login to the remote server and create a bare repository:

you@local ~$ ssh ~$ mkdir project.git ~$ cd project.git ~/project.git$ git init --bare
Initialized empty Git repository in /home/user/project.git/

To make the project usable by all users members of a group, say staff, also add: ~/project.git$ cd .. ~$ chgrp -hR staff project.git ~$ chmod -R g+rwXs project.git ~$ exit

Back on the local machine, clone the newly created empty repository:

you@local ~$ git clone ssh://
Cloning into 'project'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
you@local ~$ cd project
you@local ~/project$ edit      # copy or create some files
you@local ~/project$ git add . --dry-run # check what would be added
add ''
you@local ~/project$ git add .           # add all your initial files
you@local ~/project$ git commit -m 'initial commit'
[master (root-commit) 14da8ac] initial commit
 1 file changed, 1 insertion(+)
 create mode 100644
you@local ~/project$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 251 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://
 * [new branch]      master -> master
you@local ~/project$ git pull
Already up-to-date.

That’s it, now you can push and pull at will from the remote repository.