Docs / Programming & Development / How to Set Up a Git Repository on Your Server

How to Set Up a Git Repository on Your Server

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 416 views · 1 min read

Host your own Git repositories without GitHub or GitLab.

Install Git

apt install git -y

Create a Bare Repository

mkdir -p /opt/git/myproject.git\ncd /opt/git/myproject.git\ngit init --bare

Clone Remotely

From your local machine:

git clone ssh://root@YOUR_IP/opt/git/myproject.git

Push an Existing Project

cd existing-project\ngit remote add origin ssh://root@YOUR_IP/opt/git/myproject.git\ngit push -u origin main

Git Hooks

Use hooks for auto-deployment:

cat > /opt/git/myproject.git/hooks/post-receive         

Was this article helpful?