💾 Archived View for darknesscode.xyz › linux › git-server.gmi captured on 2024-07-09 at 00:21:23. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-05)

-=-=-=-=-=-=-

Install and setup a Git server

Setup a Git server

If you want to have you own and private git server follow the steps below, I use **Debian 10** at the moment of this example.

The first of all, you need is a minimal installation of *Debian*. Update the system and install git:

sudo apt install git

Create a new User

Create a new user call git and give a strong password.

sudo adduser git

Set up SSH Keys

First switch to the user git, then create a directory called .shh and a file called authorized_keys:

su git
cd
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

Now you need to add your public ssh key to your sever

Open the authorized_key file

sudo vim .ssh/authorized_keys

And copy you public ssh key, save and close. Now you are able to get into your server without password.

Create a bare repository

In this example, I used the home directory for the repositories. In the home git user create a new directory

mkdir rapositoryname.git

Switch to the new directory

cd repositoryname.gt

Now create a new empty repository

git init --bare

You will see something like this

Initialized empty Git repository in /home/git/repositoryname.git/

Git push

Now that you have your new repo, it's time to test it out.

In you computer got to repositoryname directory and initialized the repo

git init

You will see something like this

Initialized empty Git repository in /home/user/repositoryname.git/

Now you can do your first commit and push the repo to your private server, using this commands

git add .
git commit -m "First Commit"
git remote add origin git@yourserver:~/repositoryname.git
git push -u origin master

This git server will work only over ssh. Test it out it's good to have your own git server for private projects. There are some protocols that can be used to make the git server public.

Git Daemon

I like to use this protocol to make some of my repos public from my git server. Is easy to setup and the cloning method is:

git clone git://server:/reponame.git

Setup

To enable the git daemon

git daemon --reuseaddr --base-path=/srv/git/ /srv/git/

You need to change the path of you repos directory

Since i using **Debian**, systemd is the init system, Simply place a file in **/etc/systemd/system/git-daemon.service** with these content

[Unit]
Description=Start Git Daemon

[Service]
ExecStart=/usr/bin/git daemon --reuseaddr --base-path=/srv/git/ /srv/git/

Restart=always
RestartSec=500ms

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=git-daemon

User=git
Group=git

[Install]
WantedBy=multi-user.target

Then you need to enable and start the service

systemctl enable git-daemon
systemctl start git-daemon

Next, you have to tell Git which repositories to allow unauthenticated Git server-based access to. You can do this in each repository by creating a file named git-daemon-export-ok, for that just run

touch git-daemon-export-ok

Inside of the repository you wants to make public.

----------

Home

Linux

Notes

MicroLog

----------

© DarknessCode