Hosting private or shared git repositories without dependencies

Tools like Gitea/GitLab/cgit exist to be able to manage and browse code repositories in a simple way. However, I prefer to have as few dependencies as possible. For hosting my own private or shared git repositories it would be sufficient to set up some bare repositores on a target machine. The main hassle is to create new repositories there or assign permissions. But is it really a problem?

Putting an existing repository from a local machine into the remote

git clone --bare my_project my_project.git
scp -r my_project.git

Making a remote repository shared by a group of users

Access the folder via SSH:

cd /srv/git

Running the following command will allow any user on the machine within the group name_of_group to access and push to this repository. Additionally, the default branch name is main instead of master.

git init --bare --shared=name_of_group
git symbolic-ref HEAD refs/heads/main

Remove a branch in Git

Delete a local branch:

git branch -d branch-name

Delete a remote branch:

git push origin --delete branch-name-on-remote

Send and receive patches

There are 2 ways of generating patches with git. The first one is to generate a git diff with:

# Send the last commit
git diff HEAD~1 > name.of.patch

# Send the patch since a given commit with hash: 01020304
git diff 01020304 > name.of.patch

If git-send-email is correctly configured we can send a mail directly with our patch:

git send-email --to="" HEAD^

To apply patches from git diff or if the message was downloaded as an attachment use:

# Check if there are any issues with the patch.
git apply --check <patchname>

# Apply the patch.
git apply <patchname>

This will only apply the patch, meaning we need to commit the changed files afterwards. If the patch was sent with git send-email, we can send the entire email to git am which will update the index list with all the authors. If using mutt you can pipe the email directly to the index. If not, download the full mail and save it somewhere in your path and then:

git am pathname.mail