git-techknowledge.in

How to Setup and Configure Git Server on Ubuntu 24.04

Git is a versioning system developed by Linus Torvalds, the founder of Linux. If you’re working on team projects, version control is a must. Git is the most widely used distributed version control system, and setting up your own Git server allows you to host private repositories securely. In this guide, we’ll walk you through setting up and configuring a Git server on Ubuntu 24.04.

Step 1: Update Your System

First, log in to your Ubuntu 24.04 server and update the package list:

sudo apt update && sudo apt upgrade -y

Step 2: Install Git

Now, install Git on your server:

sudo apt install git -y

Verify installation:

git --version

Step 3: Create a Git User

It’s best practice to create a dedicated user for managing Git repositories:

sudo adduser git

You can now switch to this user:

su - git

Step 4: Create a Bare Repository

A bare repository is the central repo that stores project history but no working directory. Create one using:

mkdir myproject.git
cd myproject.git
git init --bare

This repository will act as the remote repository for your team.

Step 5: Configure SSH Access

To allow developers to push and pull code securely, enable SSH authentication.

On each developer’s machine, generate an SSH key if not already created:

ssh-keygen -t ed25519 -C "your_email@example.com"

Copy the public key (~/.ssh/id_ed25519.pub) to the Git server:

ssh-copy-id git@your_server_ip

Now developers can connect to the server securely.

Step 6: Clone and Push Code

Developers can now clone the repository:

git clone git@your_server_ip:/home/git/myproject.git

They can push their code using:

git add .
git commit -m "Initial commit"
git push origin main

Step 7: Secure and Manage Repositories

  • Use firewall rules to allow only SSH connections.
  • Keep Git updated.
  • Create separate repositories for different projects.

Final Thoughts

Setting up your own Git server on Ubuntu 24.04 is a great way to manage private projects with full control over access and security. This is especially useful for startups and small teams who want to keep their codebase private without relying on third-party platforms like GitHub or GitLab.

👉 If you’re new to Linux administration, check out our guide on Essential Linux Commands for Beginners .

👉 For more advanced Git configuration, visit the official Git documentation.

Leave a Comment

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