git.m455.casa

m455.casa

clone url: git://git.m455.casa/m455.casa


html/posts/setting-up-a-git-forge-with-gitea.html

1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
3 <head>
4 <meta charset="utf-8" />
5 <meta name="generator" content="pandoc" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7 <title>Setting up a Git forge with Gitea</title>
8 <style>
9 code{white-space: pre-wrap;}
10 span.smallcaps{font-variant: small-caps;}
11 span.underline{text-decoration: underline;}
12 div.column{display: inline-block; vertical-align: top; width: 50%;}
13 div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14 ul.task-list{list-style: none;}
15 </style>
16 <link rel="stylesheet" href="/assets/archive.css">
17 </head>
18 <body>
19 <main>
20 <h2 id="setting-up-a-git-forge-with-gitea">Setting up a Git forge with Gitea</h2>
21 <p>2021-01-06 00:00</p>
22 <p>This page will guide you through setting up a Git forge using <a href="https://gitea.io/">Gitea</a>.</p>
23 <h3 id="page-overview">Page overview</h3>
24 <!-- vim-markdown-toc GFM -->
25 <ul>
26 <li><a href="#acknowledgements">Acknowledgements</a></li>
27 <li><a href="#reasoning-for-this-guide">Reasoning for this guide</a></li>
28 <li><a href="#page-conventions">Page conventions</a></li>
29 <li><a href="#assumptions">Assumptions</a></li>
30 <li><a href="#requirements">Requirements</a></li>
31 <li><a href="#preparing-your-system">Preparing your system</a>
32 <ul>
33 <li><a href="#setting-up-dns-records-on-digitalocean">Setting up DNS records on DigitalOcean</a>
34 <ul>
35 <li><a href="#to-setup-dns-records-on-digitalocean">To setup DNS records on DigitalOcean</a></li>
36 </ul></li>
37 <li><a href="#creating-a-git-user">Creating a git user</a>
38 <ul>
39 <li><a href="#to-create-a-git-user">To create a git user</a></li>
40 </ul></li>
41 <li><a href="#adding-the-git-user-to-your-ssh-servers-allowedusers-list">Adding the git user to your SSH server’s AllowedUsers list</a>
42 <ul>
43 <li><a href="#to-add-the-git-user-to-your-ssh-servers-allowedusers-list">To add the git user to your SSH server’s AllowedUsers list</a></li>
44 </ul></li>
45 <li><a href="#creating-the-required-directories">Creating the required directories</a>
46 <ul>
47 <li><a href="#to-create-the-required-directories">To create the required directories</a></li>
48 </ul></li>
49 </ul></li>
50 <li><a href="#setting-up-gitea">Setting up Gitea</a>
51 <ul>
52 <li><a href="#downloading-gitea">Downloading Gitea</a>
53 <ul>
54 <li><a href="#to-download-gitea">To download Gitea</a></li>
55 </ul></li>
56 <li><a href="#installing-gitea">Installing Gitea</a>
57 <ul>
58 <li><a href="#to-install-gitea">To install Gitea</a></li>
59 </ul></li>
60 <li><a href="#auto-starting-gitea-on-system-boot">Auto-starting Gitea on system boot</a>
61 <ul>
62 <li><a href="#to-auto-start-gitea-on-system-boot">To auto-start Gitea on system boot</a></li>
63 </ul></li>
64 </ul></li>
65 <li><a href="#setting-up-nginx">Setting up nginx</a>
66 <ul>
67 <li><a href="#adding-a-reverse-proxy">Adding a reverse proxy</a>
68 <ul>
69 <li><a href="#to-add-a-reverse-proxy">To add a reverse proxy</a></li>
70 </ul></li>
71 <li><a href="#setting-up-your-git-domain-with-certbot">Setting up your git domain with certbot</a>
72 <ul>
73 <li><a href="#to-setup-up-your-git-domain-with-certbot">To setup up your git domain with certbot</a></li>
74 </ul></li>
75 </ul></li>
76 <li><a href="#finalizing-your-gitea-setup">Finalizing your Gitea setup</a>
77 <ul>
78 <li><a href="#accessing-the-web-interface">Accessing the web interface</a>
79 <ul>
80 <li><a href="#to-access-the-web-interface">To access the web interface</a></li>
81 </ul></li>
82 <li><a href="#removing-the-write-permission-for-the-git-user">Removing the write permission for the git user</a>
83 <ul>
84 <li><a href="#to-remove-the-write-permission-for-the-git-user">To remove the write permission for the git user</a></li>
85 </ul></li>
86 <li><a href="#setting-up-fail2ban">Setting up fail2ban</a>
87 <ul>
88 <li><a href="#to-setup-fail2ban">To setup fail2ban</a></li>
89 </ul></li>
90 </ul></li>
91 <li><a href="#tweaking-gitea">Tweaking Gitea</a>
92 <ul>
93 <li><a href="#disabling-registrations">Disabling registrations</a>
94 <ul>
95 <li><a href="#to-disable-registrations">To disable registrations</a></li>
96 </ul></li>
97 <li><a href="#changing-the-default-branch-name">Changing the default branch name</a>
98 <ul>
99 <li><a href="#to-change-the-default-branch-name">To change the default branch name</a></li>
100 </ul></li>
101 <li><a href="#setting-up-garbage-collection">Setting up garbage collection</a>
102 <ul>
103 <li><a href="#to-setup-garbage-collection">To setup garbage collection</a></li>
104 </ul></li>
105 </ul></li>
106 </ul>
107 <!-- vim-markdown-toc -->
108 <h3 id="acknowledgements">Acknowledgements</h3>
109 <p>Most of the documentation found here was referenced from <a href="https://docs.gitea.io/en-us/">Gitea’s documentation</a>.</p>
110 <h3 id="reasoning-for-this-guide">Reasoning for this guide</h3>
111 <p>As someone who is learning how to maintain servers and online services, I had a bit of trouble following the documentation, because the documentation for setting up Gitea wasn’t as linear as I was used to. I found myself jumping back and forth between the navigation sidebar, so I decided to create a more linear set of instructions for setting up Gitea for other people who had trouble with setting up Gitea.</p>
112 <h3 id="page-conventions">Page conventions</h3>
113 <ul>
114 <li><strong>Note</strong>: Signifies additional information</li>
115 <li><strong>Tip</strong>: Signifies an alternative procedure for completing a step</li>
116 <li><strong>Warning</strong>: Signifies that damage, such as data loss, may occur</li>
117 <li><strong>Example</strong>: Shows how a procedure would be performed in a real scenario</li>
118 <li><code>Inline code and code blocks</code>: Signify package names, filenames, file contents, or commands</li>
119 <li><code>yourdomain.com</code>: Signifies that you should replace <code>yourdomain.com</code> with your own domain name.</li>
120 </ul>
121 <h3 id="assumptions">Assumptions</h3>
122 <p>This guide assumes:</p>
123 <ul>
124 <li>You are using a Ubuntu server on a DigialOcean droplet</li>
125 <li>You are using nginx to serve your web content</li>
126 <li>You manage your SSL/TLS certificates with certbot</li>
127 <li>You have your domain name setup with DigitalOcean’s name servers</li>
128 <li>You have your SSH keys setup with your server</li>
129 <li>You have root access to your server</li>
130 </ul>
131 <h3 id="requirements">Requirements</h3>
132 <ul>
133 <li>git</li>
134 <li>sqlite3</li>
135 <li>fail2ban</li>
136 </ul>
137 <h3 id="preparing-your-system">Preparing your system</h3>
138 <p>Before using Gitea, you will need to prepare DNS records and create a git user.</p>
139 <p>This section consists of the following topics:</p>
140 <ul>
141 <li><a href="#setting-up-dns-records-on-digitalocean">Setting up DNS records on DigitalOcean</a></li>
142 <li><a href="#creating-a-git-user">Creating a git user</a></li>
143 <li><a href="#adding-the-git-user-to-your-ssh-servers-allowedusers-list">Adding the git user to your SSH server’s AllowedUsers list</a></li>
144 <li><a href="#creating-the-required-directories">Creating the required directories</a></li>
145 </ul>
146 <h4 id="setting-up-dns-records-on-digitalocean">Setting up DNS records on DigitalOcean</h4>
147 <p>Setting up DNS records for a <code>git.yourdomain.com</code> allows you to redirect users back to your server, so nginx can redirect users to specific paths or ports on your server.</p>
148 <h5 id="to-setup-dns-records-on-digitalocean">To setup DNS records on DigitalOcean</h5>
149 <ol type="1">
150 <li>Add an A record for <code>git.yourdomain.com</code> to your DigitalOcean droplet</li>
151 <li>Add an AAAA record for <code>git.yourdomain.com</code> to your DigitalOcean droplet</li>
152 </ol>
153 <h4 id="creating-a-git-user">Creating a git user</h4>
154 <p>Creating a git user allows you to run Gitea as a different user from root. This is a safer option, especially if you intend to push to your repositories using SSH or have multiple users on your Gitea instance.</p>
155 <h5 id="to-create-a-git-user">To create a git user</h5>
156 <ol type="1">
157 <li><p>Run the following command:</p>
158 <pre><code> sudo adduser \
159 --system \
160 --shell /bin/bash \
161 --gecos &#39;Git Version Control&#39; \
162 --group \
163 --disabled-password \
164 --home /home/git \
165 git</code></pre></li>
166 </ol>
167 <p><strong>Source</strong>: Gitea’s <a href="https://docs.gitea.io/en-us/install-from-binary/#prepare-environment">Prepare environment</a> section.</p>
168 <h4 id="adding-the-git-user-to-your-ssh-servers-allowedusers-list">Adding the git user to your SSH server’s AllowedUsers list</h4>
169 <p>Pushing Git commits over SSH is convenient because you don’t need to enter a username and password like you would over HTTPS. You will need to add the git user to your SSH server’s <code>AllowedUsers</code> list to use Git over SSH.</p>
170 <h5 id="to-add-the-git-user-to-your-ssh-servers-allowedusers-list">To add the git user to your SSH server’s AllowedUsers list</h5>
171 <ol type="1">
172 <li>Open <code>/etc/ssh/sshd_config</code></li>
173 <li>Find <code>AllowUsers</code></li>
174 <li>Add <code>git</code> to list of users</li>
175 </ol>
176 <h4 id="creating-the-required-directories">Creating the required directories</h4>
177 <p>Gitea doesn’t have the permissions to create directories in root directories, so you will have to do this yourself.</p>
178 <h5 id="to-create-the-required-directories">To create the required directories</h5>
179 <ol type="1">
180 <li>Run <code>sudo mkdir -p /var/lib/gitea/{custom,data,log}</code></li>
181 <li>Run <code>sudo chown -R git:git /var/lib/gitea/</code></li>
182 <li>Run <code>sudo chmod -R 750 /var/lib/gitea/</code></li>
183 <li>Run <code>sudo mkdir /etc/gitea</code></li>
184 <li>Run <code>sudo chown root:git /etc/gitea</code></li>
185 <li>Run <code>sudo chmod 770 /etc/gitea</code></li>
186 </ol>
187 <p><strong>Source</strong>: Gitea’s <a href="https://docs.gitea.io/en-us/install-from-binary/#create-required-directory-structure">Create required directory structure</a> section.</p>
188 <h3 id="setting-up-gitea">Setting up Gitea</h3>
189 <p>Gitea simplifies installation by providing a binary. You can download this binary and move it to a globally-accessible directory.</p>
190 <p>This section contains the following topics:</p>
191 <ul>
192 <li><a href="#downloading-gitea">Downloading Gitea</a></li>
193 <li><a href="#installing-gitea">Installing Gitea</a></li>
194 <li><a href="#auto-starting-gitea-on-system-boot">Auto-starting Gitea on system boot</a></li>
195 </ul>
196 <h4 id="downloading-gitea">Downloading Gitea</h4>
197 <p>Downloading Gitea will provide you with the proper resources for running Gitea.</p>
198 <h5 id="to-download-gitea">To download Gitea</h5>
199 <ol type="1">
200 <li>Run <code>sudo su git</code></li>
201 <li>Run <code>cd</code></li>
202 <li>Run <code>wget -O gitea https://dl.gitea.io/gitea/1.13.1/gitea-1.13.1-linux-amd64</code></li>
203 <li>Run <code>chmod +x gitea</code></li>
204 </ol>
205 <aside class="border">
206 <p>
207 <strong>Note</strong>: In this section, we are downloading Gitea version 1.13.1. This guide will quickly become outdated. For the latest version, check out Gitea’s <a href="https://docs.gitea.io/en-us/install-from-binary/#download">Install from binary</a> section.
208 </p>
209 </aside>
210 <p><strong>Source</strong>: Gitea’s <a href="https://docs.gitea.io/en-us/install-from-binary/#download">Download</a> section.</p>
211 <h4 id="installing-gitea">Installing Gitea</h4>
212 <p>Installing Gitea will make the Gitea binary globally accessible on your system.</p>
213 <h5 id="to-install-gitea">To install Gitea</h5>
214 <ol type="1">
215 <li>Run <code>cp gitea /usr/local/bin/gitea</code></li>
216 </ol>
217 <p><strong>Source</strong>: Gitea’s <a href="https://docs.gitea.io/en-us/install-from-binary/#copy-gitea-binary-to-global-location">Copy Gitea binary to global location</a> section.</p>
218 <h4 id="auto-starting-gitea-on-system-boot">Auto-starting Gitea on system boot</h4>
219 <p>Auto-starting Gitea can be convenient if you need to restart your server after updates or changes, and have several other services that you need to auto-start.</p>
220 <h5 id="to-auto-start-gitea-on-system-boot">To auto-start Gitea on system boot</h5>
221 <ol type="1">
222 <li><p>Add the following in <code>/etc/systemd/system/gitea.service</code>:</p>
223 <pre><code> [Unit]
224 Description=Gitea (Git with a cup of tea)
225 After=syslog.target
226 After=network.target
227 ###
228 # Don&#39;t forget to add the database service requirements
229 ###
230 #
231 #Requires=mysql.service
232 #Requires=mariadb.service
233 #Requires=postgresql.service
234 #Requires=memcached.service
235 #Requires=redis.service
236 #
237 ###
238 # If using socket activation for main http/s
239 ###
240 #
241 #After=gitea.main.socket
242 #Requires=gitea.main.socket
243 #
244 ###
245 # (You can also provide gitea an http fallback and/or ssh socket too)
246 #
247 # An example of /etc/systemd/system/gitea.main.socket
248 ###
249 ##
250 ## [Unit]
251 ## Description=Gitea Web Socket
252 ## PartOf=gitea.service
253 ##
254 ## [Socket]
255 ## Service=gitea.service
256 ## ListenStream=&lt;some_port&gt;
257 ## NoDelay=true
258 ##
259 ## [Install]
260 ## WantedBy=sockets.target
261 ##
262 ###
263
264 [Service]
265 # Modify these two values and uncomment them if you have
266 # repos with lots of files and get an HTTP error 500 because
267 # of that
268 ###
269 #LimitMEMLOCK=infinity
270 #LimitNOFILE=65535
271 RestartSec=2s
272 Type=simple
273 User=git
274 Group=git
275 WorkingDirectory=/var/lib/gitea/
276 # If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
277 # (manually creating /run/gitea doesn&#39;t work, because it would not persist across reboots)
278 #RuntimeDirectory=gitea
279 ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
280 Restart=always
281 Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
282 # If you install Git to directory prefix other than default PATH (which happens
283 # for example if you install other versions of Git side-to-side with
284 # distribution version), uncomment below line and add that prefix to PATH
285 # Don&#39;t forget to place git-lfs binary on the PATH below if you want to enable
286 # Git LFS support
287 #Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin
288 # If you want to bind Gitea to a port below 1024, uncomment
289 # the two values below, or use socket activation to pass Gitea its ports as above
290 ###
291 #CapabilityBoundingSet=CAP_NET_BIND_SERVICE
292 #AmbientCapabilities=CAP_NET_BIND_SERVICE
293 ###
294
295 [Install]
296 WantedBy=multi-user.target</code></pre></li>
297 <li><p>Run <code>sudo systemctl enable gitea</code></p></li>
298 <li><p>Run <code>sudo systemctl start gitea</code></p></li>
299 </ol>
300 <p><strong>Source</strong>: Gitea’s <a href="https://docs.gitea.io/en-us/linux-service/#using-systemd">Using systemd</a> section.</p>
301 <h3 id="setting-up-nginx">Setting up nginx</h3>
302 <p>Gitea is a web application, so you will need to setup nginx to serve the interface.</p>
303 <p>This section consists of the following topics:</p>
304 <ul>
305 <li><a href="#adding-a-reverse-proxy">Adding a reverse proxy</a></li>
306 <li><a href="#setting-up-your-git-domain-with-certbot">Setting up your git domain with certbot</a></li>
307 </ul>
308 <h4 id="adding-a-reverse-proxy">Adding a reverse proxy</h4>
309 <p>Gitea runs on port 3000 by default, so you will need to configure nginx to redirect users to port 3000 on your server when they visit git.yourdomain.com.</p>
310 <h5 id="to-add-a-reverse-proxy">To add a reverse proxy</h5>
311 <ol type="1">
312 <li><p>Add the following in <code>/etc/nginx/sites-available/git.yourdomain.com</code> as root:</p>
313 <pre><code> server {
314 listen 80;
315 server_name git.yourdomain.com;
316
317 location / {
318 proxy_pass http://localhost:3000;
319 }
320 }</code></pre></li>
321 <li><p>Run the following command:</p>
322 <pre><code> sudo ln -s /etc/nginx/sites-available/git.yourdomain.com /etc/nginx/sites-enabled/git.yourdomain.com</code></pre></li>
323 <li><p>Run <code>sudo systemctl restart nginx</code></p></li>
324 </ol>
325 <p><strong>Source</strong>: Gitea’s <a href="https://docs.gitea.io/en-us/reverse-proxies/#nginx">Nginx</a> section.</p>
326 <h4 id="setting-up-your-git-domain-with-certbot">Setting up your git domain with certbot</h4>
327 <p>Before you can access your website, you will want to allow a secure connection before you sign up for the initial Gitea account, which will optionally be used as an administrator account as well as a regular user account.</p>
328 <h5 id="to-setup-up-your-git-domain-with-certbot">To setup up your git domain with certbot</h5>
329 <ol type="1">
330 <li>Run <code>sudo certbot</code></li>
331 <li>Follow the prompts</li>
332 <li>Run <code>sudo systemctl restart nginx</code></li>
333 </ol>
334 <h3 id="finalizing-your-gitea-setup">Finalizing your Gitea setup</h3>
335 <p>Before you can use Gitea, you will need to access the web installer. The web installer will guide you through a setup process, and user registration. The first user who signs up has the option to become an administrator user who can also use Gitea as a regular user.</p>
336 <p>This section consists of the following topics:</p>
337 <ul>
338 <li><a href="#accessing-the-web-interface">Accessing the web interface</a></li>
339 <li><a href="#removing-the-write-permission-for-the-git-user">Removing the write permission for the git user</a></li>
340 <li><a href="#setting-up-fail2ban">Setting up fail2ban</a></li>
341 </ul>
342 <h4 id="accessing-the-web-interface">Accessing the web interface</h4>
343 <p>Gitea provides a web interface for configuring and installing Gitea. You can access the web interface using a web browser.</p>
344 <h5 id="to-access-the-web-interface">To access the web interface</h5>
345 <ol type="1">
346 <li><p>Navigate to <code>git.yourdomain.com/install</code> in your browser</p>
347 <aside class="border">
348 <p>
349 <p><strong>Tip</strong>: If this doesn’t work, try navigating to <code>git.yourdomain.com</code>.</p>
350 </p>
351 </aside></li>
352 <li><p>Choose SQLite</p></li>
353 <li><p>Change “SSH Server Domain” to <code>git.yourdomain.com</code></p></li>
354 <li><p>Change “Gitea Base URL” to <code>https://git.yourdomain.com</code></p></li>
355 <li><p>Choose your desired settings for the remaining configuration options</p></li>
356 <li><p>Click “Install Gitea”</p></li>
357 </ol>
358 <h4 id="removing-the-write-permission-for-the-git-user">Removing the write permission for the git user</h4>
359 <p>In previous sections, <code>/etc/gitea</code> has write permissions for the git user, so the web installer could write to the configuration file. You should change the permissions back to read-only for security purposes.</p>
360 <h5 id="to-remove-the-write-permission-for-the-git-user">To remove the write permission for the git user</h5>
361 <ol type="1">
362 <li>Run <code>sudo chmod 750 /etc/gitea</code></li>
363 <li>Run <code>sudo chmod 640 /etc/gitea/app.ini</code></li>
364 </ol>
365 <p><strong>Source</strong>: Gitea’s <a href="https://docs.gitea.io/en-us/install-from-binary/#create-required-directory-structure">Create required directory structure</a> section.</p>
366 <h4 id="setting-up-fail2ban">Setting up fail2ban</h4>
367 <p>fail2ban protects your server against repeated attacks if you have a publicly-facing authentication system, such as a sign-in page or a register page.</p>
368 <p>In this guide, although we will be disabling the registration page, there will still be a sign-in page that we need to protect.</p>
369 <h5 id="to-setup-fail2ban">To setup fail2ban</h5>
370 <ol type="1">
371 <li><p>Add the following to <code>/etc/fail2ban/filter.d/gitea.conf</code> as root:</p>
372 <pre><code> [Definition]
373 failregex = .*(Failed authentication attempt|invalid credentials|Attempted access of unknown user).* from &lt;HOST&gt;
374 ignoreregex =</code></pre></li>
375 <li><p>Add the following to <code>/etc/fail2ban/jail.d/gitea.conf</code> as root:</p>
376 <pre><code> [gitea]
377 enabled = true
378 filter = gitea
379 logpath = /var/lib/gitea/log/gitea.log
380 maxretry = 10
381 findtime = 3600
382 bantime = 900
383 action = iptables-allports</code></pre></li>
384 <li><p>Run <code>touch /var/lib/gitea/log/gitea.log</code> as root</p></li>
385 <li><p>Run <code>systemctl restart fail2ban</code></p></li>
386 </ol>
387 <p><strong>Source</strong>: Gitea’s <a href="https://docs.gitea.io/en-us/fail2ban-setup/">Fail2ban setup to block users after failed login attempts</a> page.</p>
388 <h3 id="tweaking-gitea">Tweaking Gitea</h3>
389 <p>Gitea provides an <code>app.ini</code> file that allows you to modify Gitea to your liking.</p>
390 <p>This section consists of the following topics:</p>
391 <ul>
392 <li><a href="#disabling-registrations">Disabling registrations</a></li>
393 <li><a href="#changing-the-default-branch-name">Changing the default branch name</a></li>
394 <li><a href="#setting-up-garbage-collection">Setting up garbage collection</a></li>
395 </ul>
396 <h4 id="disabling-registrations">Disabling registrations</h4>
397 <p>After you created the first user, you can disable registrations to prevent unknown users from registering on your Gitea.</p>
398 <aside class="border">
399 <p>
400 <strong>Note</strong>: If you wish to add a user in the future, you can use Gitea’s built-in “Create User Account” button found in “Site Administration” &gt; “User Accounts”.
401 </p>
402 </aside>
403 <h5 id="to-disable-registrations">To disable registrations</h5>
404 <ol type="1">
405 <li>Edit <code>/etc/gitea/app.ini</code> as root</li>
406 <li>Find the <code>[service]</code> section</li>
407 <li>Change <code>DISABLE_REGISTRATION</code>’s value to <code>true</code></li>
408 </ol>
409 <aside class="border">
410 <p>
411 <strong>Example</strong>: Your <code>[service]</code> section might look like the one below:
412 </p>
413 <pre>
414 [service]
415 REGISTER_EMAIL_CONFIRM = false
416 ENABLE_NOTIFY_MAIL = false
417 DISABLE_REGISTRATION = true
418 ALLOW_ONLY_EXTERNAL_REGISTRATION = false
419 ENABLE_CAPTCHA = false
420 REQUIRE_SIGNIN_VIEW = false
421 DEFAULT_KEEP_EMAIL_PRIVATE = false
422 DEFAULT_ALLOW_CREATE_ORGANIZATION = false
423 DEFAULT_ENABLE_TIMETRACKING = false
424 NO_REPLY_ADDRESS = noreply.localhost
425 </pre>
426 </aside>
427 <h4 id="changing-the-default-branch-name">Changing the default branch name</h4>
428 <p>Gitea allows you to set a default branch name when creating new repositories.</p>
429 <h5 id="to-change-the-default-branch-name">To change the default branch name</h5>
430 <ol type="1">
431 <li>Edit <code>/etc/gitea/app.ini</code> as root</li>
432 <li>Find the <code>[repository]</code> section</li>
433 <li>Change <code>DEFAULT_BRANCH</code>’s value to <code>main</code></li>
434 </ol>
435 <aside class="border">
436 <p>
437 <strong>Example</strong>: Your <code>[repository]</code> section might look like the one below:
438 </p>
439 <pre>
440 [repository]
441 ROOT = /home/git/gitea-repositories
442 DEFAULT_BRANCH = main
443 </pre>
444 </aside>
445 <aside class="border">
446 <p>
447 <strong>Note</strong>: Other common default branch names could be <code>trunk</code> or <code>default</code>
448 </p>
449 </aside>
450 <h4 id="setting-up-garbage-collection">Setting up garbage collection</h4>
451 <p>Setting a garbage collection value will prevent incremental memory consumption over time. Setting this keeps CPU usage at a constant level. Without this set, the CPU usage rises over time.</p>
452 <h5 id="to-setup-garbage-collection">To setup garbage collection</h5>
453 <ol type="1">
454 <li>Edit <code>/etc/gitea/app.ini</code> as root</li>
455 <li>Find the <code>[session]</code> section</li>
456 <li>Add <code>GC_INTERVAL_TIME = 86400</code> under <code>PROVIDER = file</code></li>
457 </ol>
458 <aside class="border">
459 <p>
460 <strong>Example</strong>: Your <code>[session]</code> section might look like the one below:
461 </p>
462 <pre>
463 [session]
464 PROVIDER = file
465 GC_INTERVAL_TIME = 86400
466 </pre>
467 </aside>
468 </main>
469 </body>
470 </html>