<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Self-Hosted-Git on KnightLi Blog</title>
        <link>https://www.knightli.com/en/tags/self-hosted-git/</link>
        <description>Recent content in Self-Hosted-Git on KnightLi Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <lastBuildDate>Wed, 07 Dec 2022 00:00:00 +0000</lastBuildDate><atom:link href="https://www.knightli.com/en/tags/self-hosted-git/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>Build a Git Server on Synology NAS and Back It Up with Hyper Backup</title>
        <link>https://www.knightli.com/en/2022/12/07/synology-git-server-hyper-backup/</link>
        <pubDate>Wed, 07 Dec 2022 00:00:00 +0000</pubDate>
        
        <guid>https://www.knightli.com/en/2022/12/07/synology-git-server-hyper-backup/</guid>
        <description>&lt;p&gt;Synology NAS can be used as a lightweight private Git server. For personal projects or a small team, this is often enough: repositories stay inside the LAN, access can be managed through NAS accounts, and the data can be backed up with Synology&amp;rsquo;s built-in tools.&lt;/p&gt;
&lt;p&gt;This note records the basic setup idea and the backup workflow with Hyper Backup.&lt;/p&gt;
&lt;h2 id=&#34;install-git-server&#34;&gt;Install Git Server
&lt;/h2&gt;&lt;p&gt;Open Package Center on Synology DSM and install the Git Server package.&lt;/p&gt;
&lt;p&gt;After installation, open Git Server and allow the required users to use Git over SSH. The NAS account must have SSH access and permission to the folder where repositories are stored.&lt;/p&gt;
&lt;h2 id=&#34;prepare-a-repository-directory&#34;&gt;Prepare A Repository Directory
&lt;/h2&gt;&lt;p&gt;Create a shared folder or a subdirectory for Git repositories, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/volume1/git
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Inside this directory, create bare repositories:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git init --bare project.git
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;A bare repository does not contain a working tree. It is suitable for use as a remote repository.&lt;/p&gt;
&lt;h2 id=&#34;connect-from-a-client&#34;&gt;Connect From A Client
&lt;/h2&gt;&lt;p&gt;From another machine, clone the repository through SSH:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git clone user@nas-ip:/volume1/git/project.git
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;You can also add it as a remote in an existing local project:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git remote add origin user@nas-ip:/volume1/git/project.git
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push -u origin master
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If SSH uses a non-standard port, specify it in the SSH configuration or use a custom remote URL.&lt;/p&gt;
&lt;h2 id=&#34;permissions&#34;&gt;Permissions
&lt;/h2&gt;&lt;p&gt;Make sure the repository directory belongs to the correct user or group. If multiple users need access, assign them to a shared group and grant read/write permission to the Git folder.&lt;/p&gt;
&lt;p&gt;When push fails, check these items first:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;whether SSH login works;&lt;/li&gt;
&lt;li&gt;whether the user is allowed in Git Server;&lt;/li&gt;
&lt;li&gt;whether the folder permission is writable;&lt;/li&gt;
&lt;li&gt;whether the repository was initialized as bare;&lt;/li&gt;
&lt;li&gt;whether the remote URL is correct.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;back-up-with-hyper-backup&#34;&gt;Back Up With Hyper Backup
&lt;/h2&gt;&lt;p&gt;After repositories are stored on the NAS, configure Hyper Backup to back up the Git directory.&lt;/p&gt;
&lt;p&gt;In Hyper Backup:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a new backup task.&lt;/li&gt;
&lt;li&gt;Select the destination, such as another disk, another NAS, rsync server or cloud storage.&lt;/li&gt;
&lt;li&gt;Select the Git repository folder.&lt;/li&gt;
&lt;li&gt;Configure the schedule.&lt;/li&gt;
&lt;li&gt;Enable version retention if needed.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This protects the repository data against disk failure, accidental deletion or wrong pushes.&lt;/p&gt;
&lt;h2 id=&#34;restore-notes&#34;&gt;Restore Notes
&lt;/h2&gt;&lt;p&gt;When restoring, recover the whole bare repository directory. After restoration, test with:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git clone user@nas-ip:/volume1/git/project.git
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If cloning works, the repository is usable again.&lt;/p&gt;
&lt;h2 id=&#34;summary&#34;&gt;Summary
&lt;/h2&gt;&lt;p&gt;Synology Git Server is simple, but it is enough for many private repositories. The important points are SSH access, correct folder permissions, bare repositories and a reliable Hyper Backup task.&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
