Create & Populate a git server

In this page

  1. Create a basic git server
  2. Create a bare repository
  3. Populate the server

1. Create a basic git server

Add git "user"

Log into to the server computer with an user name that has, at least 'sudo' powers. This computer should also have ssh running. (see ssh).

$ sudo useradd -m -d /home/git git  # Add git user
$ cd /home/git
$ sudo su git                       # log in as git (locked account)
$ mkdir .ssh                        # Create the folder for ssh keys

At this point, add public keys for all users that will use the repository. For information on how to add the keys, go back to ssh

2. Create a bare repository

Create repository

Still logged into the server as git user, create a repository. Here it is in /repo/git. Could be in /opt, /var, your choice.

$ cd /repo/git      # Go to the root git directory
$ mkdir project.git # Create a folder to hold one project (use .git ext)
$ cd project.git
$ git --bare init   # Create a bare (no work dir) server (in project.git)

3. Populate the server

Populating the server for the first time

In the local computer (not the server) log in with an user for which the public ssh key was added to the git account.

$ cd anyproject
$ git init                          # Initialize local repository (if needed)
$ git add .                         # Add all files to be tracked (if needed)
$ git commit -m "Initial commit"    # Commit the files (if needed)
$ git remote add origin \
   git@<server>:/repo/git/proj.git  # Link remote proj to local nickname (origin)
$ git push origin master            # Push local into server as a master branch