How do I set up a Git server on Linux

Setting up a Git server on Linux is a great way to manage your code and collaboration efficiently. Below are the steps you need to follow to set up your own Git server.

Step 1: Install Git

First, you need to install Git on your Linux server. Use the package manager for your distribution. For example, on Ubuntu, you can run:

sudo apt-get update sudo apt-get install git

Step 2: Create a Git User

It's a good security practice to create a separate user for Git operations:

sudo adduser git

Step 3: Initialize a Bare Repository

A bare repository is necessary for a Git server. You can create one as follows:

sudo mkdir -p /home/git/repositories/myproject.git cd /home/git/repositories/myproject.git sudo git init --bare

Step 4: Set Permissions

Make sure the Git user has the appropriate permissions on the repository:

sudo chown -R git:git /home/git/repositories/myproject.git

Step 5: Add SSH Access

To allow collaborators to push to your repository, utilize SSH keys for secure access:

sudo mkdir /home/git/.ssh sudo nano /home/git/.ssh/authorized_keys

Step 6: Accessing the Git Repository

Collaborators can now clone the repository using:

git clone git@yourserver.com:/home/git/repositories/myproject.git

Keywords: Git server Linux setup Git server