You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
3.4 KiB
HTML
82 lines
3.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="description" content="To keep control of your version control, and not be reliant on any third parties, a git server can be easily self hosted. Side benefit, you don't need to install anything on your server other than git, and ssh.">
|
|
<meta name="author" content="Nathan (Aney) Steel">
|
|
<meta name="theme-color" content="white">
|
|
<meta name="theme-color" content="black">
|
|
<link rel="stylesheet" type="text/css" href="/main.css">
|
|
<link rel="icon" type="image/png" href="/images/favicon.svg">
|
|
<title>Git server setup</title>
|
|
</head>
|
|
|
|
<body>
|
|
<header>
|
|
<h1>Git server setup</h1>
|
|
<hr/>
|
|
<nav>
|
|
<a href="/">home</a>
|
|
<a href="/equipment.html">equipment</a>
|
|
<a href="/projects.html">projects</a>
|
|
<a href="/blog/">blog</a>
|
|
<a href="/sitemap.html">misc</a>
|
|
<a href="/support.html">support</a>
|
|
</nav>
|
|
<hr/>
|
|
</header>
|
|
|
|
<main>
|
|
<section>
|
|
<p class="intro">Self-hosted version control is great way to not be dependant of a third party to keep your git server up, or your code secure.</p>
|
|
|
|
<h2>Install Git</h2>
|
|
<p>Many Unix operating systems have git installed by default, but if not it's a simple command.</p>
|
|
<pre><code>sudo apt install git</code></pre>
|
|
|
|
<h2>Create a git user</h2>
|
|
<p>This user will be used to push/pull all your git repos</p>
|
|
<pre><code>sudo useradd -m git -d /srv/git -s /bin/bash</code></pre>
|
|
<p>Change <strong>/srv/git</strong> to the location you wish to hold your repositories.</p>
|
|
|
|
<h2>Create a repo</h2>
|
|
<p>With the user, and directory created next you'll need to create a repo.</p>
|
|
<p><em>This step will need to be repeated for each new repo you create.</em></p>
|
|
<pre><code>git init --bare repo.git</code></pre>
|
|
|
|
<h2>Enable SSH</h2>
|
|
<p>Next you'll need to set up SSH for the git user.</p>
|
|
<h3>Install and Enable SSH (If not already done)</h3>
|
|
<pre><code>sudo apt install ssh && sudo systemctl enable ssh --now</code></pre>
|
|
<h3>Create ssh key for git user</h3>
|
|
<pre><code>ssh-keygen -t ed25519</code></pre>
|
|
|
|
<h2>Use the git server</h2>
|
|
<p>With all the setup out the way, the git server is now usable as a remote for any of your git repos.</p>
|
|
<p>So on another PC...</p>
|
|
<h3>Add remote to existing repo</h3>
|
|
<pre><code>git remote add origin git@<your-server>:/<repo.git></code></pre>
|
|
<h3>Clone the repo</h3>
|
|
<pre><code>git clone git@<your-server>/:<repo.git></code></pre>
|
|
|
|
<h3>Different SSH port</h3>
|
|
<p>If you are using a different ssh port for your server hosting git, you'll need to add the following after the colon (:) to the two previous commands</p>
|
|
<pre><code><port></code></pre>
|
|
<p>Giving you something like this</p>
|
|
<pre><code>git clone git@<your-server>:<port>/<repo.git></code></pre>
|
|
|
|
<br/>
|
|
<p>From here you can use git as you would via any other provider, but with the knowledge that your remote is yours.</p>
|
|
|
|
</section>
|
|
</main>
|
|
|
|
<footer>
|
|
<hr/>
|
|
<p>Written by <a href="http://aney.co.uk" target="_blank" rel="noopener">@aney</a> with <a href="https://danluu.com/web-bloat/" target="_blank" rel="noopener">web bloat</a> in mind | <a href="https://github.com/Aney/website" target="_blank" rel="noopener">Source Code</a></p>
|
|
</footer>
|
|
</body>
|
|
</html>
|
|
|