You can easily host a remote git repository with nothing more than SSH access to a file directory.
If you'd like a webpage and lots more features, see GitLab Community Edition
Instructions for Debian; for Red Hat replace apt with dnf.
Log in to the remote server with sudo privileges. Use agent forwarding, or you will need to copy/paste your public key.
Install the git software:
sudo apt install -y git
Create the git user account:
sudo useradd -m git
Switch to the new git user; this won't work later after we configure it to use git-shell:
sudo su - git
Set up SSH directory and permissions
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
Set git defaults:
git config --global init.defaultBranch main
git config --global receive.fsckObjects true
git config --global receive.denyNonFastForwards true
git config --global receive.denyDeletes true
Return to your login user
exit
Append your SSH key to the git authorized_keys (with restrictions):
echo restrict "$(ssh-add -L)" | sudo -u git tee -a ~git/.ssh/authorized_keys > /dev/null
Log in to your local Linux / WSL system (exit).
You should be logged in to your local Linux/WSL system.
Set reference variables:
repo=your_repo_folder
server=your_remote_server
Configure your local login's global SSH key (This is only needed once)
git config --global core.sshCommand "ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes"
ssh-copy-id -i git@"${server}"
Set the remote shell to bash; later it will be set to git-shell:
ssh -A ${server} sudo usermod -s `which bash` git
Initialize a repository folder on the remote server:
ssh git@"${server}" mkdir -p "${repo}"
ssh git@"${server}" git init --bare "${repo}"
Set up the remote server as a git remote (origin) using SCP protocol:
cd ${repo}
git remote add origin git@${server}:${repo}
git remote -v
Push your repository main branch:
git push -u origin main
The current setup requires trusting users not to abuse "ssh git@$(server}" to do other things under git user. It can be locked down after repositories are set up.
Change the git user shell (from your local system):
ssh -A ${server} sudo usermod -s `which git-shell` git
Now the remote commands are restricted to git activities. If you need to add more repositories, change the shell back to bash.
More advanced features on the server can be setup under the repository hooks/ subfolder.