git.html (6402B)
1 <!DOCTYPE html> 2 <html lang="en-GB"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta name="author" content="Shipwreckt"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <title>Git server setup!</title> 8 <link rel="stylesheet" href="../../../styles.css"> 9 <link rel="icon" href="../../../Images/favi.png" type="image/x-icon"> 10 </head> 11 <body> 12 <header> 13 <nav> 14 <ul> 15 <li><a href="../../../index.html">Home</a></li> 16 <li><a href="../../../links.html">Links</a></li> 17 <li><a href="../../../projects.html">Projects</a></li> 18 <li><a href="../../../contact.html">Contact</a></li> 19 </ul> 20 </nav> 21 </header> 22 <main> 23 <h1>How to start your own epic Git server!</h1> 24 <h3>Date: 23-02-2025</h3> 25 <hr> 26 <p>Quick guide on how to set up a git server with stagic html website.</p> 27 <hr> 28 29 <h2>What you will need 📋</h2> 30 <ul> 31 <li>A computer with Linux 🐧🖥️</li> 32 <li>A VPS with Linux instaled 🐧🗄️</li> 33 <li>Some terminal knowlage 🧠</li> 34 <li>Ideally have a domain name</li> 35 </ul> 36 <hr> 37 38 <h1>Setting up Git server</h1> 39 <hr> 40 41 <li>1) Install Git</li> 42 <br> 43 <div class="code-box"> 44 <p># sudo apt install git</p> 45 </div> 46 <br> 47 48 <hr> 49 50 <li>2) Create git user.</li><br> 51 <div class="code-box"> 52 <p># sudo adduser git</p> 53 </div> 54 55 <hr> 56 57 <li>3) Now you need to add your SSh keys.</li><br> 58 <div class="code-box"> 59 <h3>On server</h3> 60 <p># su git</p> 61 <p>$ cd</p> 62 <p>$ mkdir .ssh && chmod 700 .ssh</p> 63 <p>$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys</p> 64 </div> 65 66 <br> 67 68 <div class="code-box"> 69 <h3>On computer</h3> 70 <p>$ cat .ssh/id_rsa.pub</p> 71 <pre>ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCyXwuFdbWHloGPOfFq6p5Dt..... me@shipwreckt.co.uk</pre> 72 <p>Copy and paste your ssh key to .ssh/authorized_keys on your server. 73 </div> 74 75 <p>If you want to allow other people to use your Git server, add their SSH keys alongside yours.</p> 76 77 <hr> 78 79 <li>4) Nearly done, now all you need to do is make a git repo.</li><br> 80 <div class="code-box"> 81 <p># chown git:git /srv/git</p> 82 <p># su git</p> 83 <p>$ cd /srv/git</p> 84 <p>$ mkdir yourrepo.git</p> 85 <p>$ cd yourrepo.git</p> 86 <p>$ git init --bare</p> 87 </div> 88 89 <hr> 90 91 <li>5) Time to add your server to your local repo</li> 92 <div class="code-box"> 93 <h3>On computer</h3> 94 <p>$ cd yourrepo</p> 95 <p>$ git init</p> 96 <p>$ git add .</p> 97 <p>$ git commit -m 'Initial commit'</p> 98 <p>$ git remote add origin git@gitserver:/srv/git/project.git</p> 99 <p>$ git push origin master</p> 100 </div> 101 102 <p>If you already have a Git repository from another server, you can do the following to add your new Git server alongside your old one.</p> 103 104 <div class="code-box"> 105 <h3>On computer</h3> 106 <p>$ cd yourrepo</p> 107 <p>$ git remote add server git@gitserver:/srv/git/project.git</p> 108 <p>$ git push server master && git push origin master</p> 109 </div> 110 111 <p>You can now do this for all of your repos!</p> 112 113 <hr> 114 115 <li>6) If you want to enable anybody to clone from your website do the following!</li> 116 117 <div class="code-box"> 118 <p># sudo git daemon --reuseaddr --base-path=/srv/git/ /srv/git/ &</p> 119 <p># sudo systemctl enable git-daemon</p> 120 <p># sudo systemctl start git-daemon</p> 121 <p># su git</p> 122 <p>touch /srv/git/project.git/git-daemon-export-ok</p> 123 </div> 124 125 <p>Cloning your git repo</p> 126 <div class="code-box"> 127 <h3>On computer</h3> 128 <p>git clone git://your-server-ip-address/repository.git</p> 129 </div> 130 <p>Now you should be able to be able to clone without a ssh key!</p> 131 132 <hr> 133 <h1>Setting up Stagit for personal git website</h1> 134 <p>Now that you have a Git server, you probably want a way to show off all of your repositories. I personally use Stagit for this because it is lightweight and stylish. I will assume you know how to make a website using Apache or Nginx.</p> 135 136 <hr> 137 <li>1) First you need to install stagit, I have my own custom fork to make it easier to setup.</li> 138 <div class="code-box"> 139 <p># cd /var/www</p> 140 <p># git clone git://shipwreckt.co.uk/stagit-fork.git</p> 141 <p># mkdir git</p> 142 <p># chown git:git git</p> 143 <p># mv stagit-fork/* git</p> 144 <p># cd git</p> 145 <p># sudo make clean install</p> 146 </div> 147 148 <hr> 149 <li>2) Setup website.</li> 150 <div class="code-box"> 151 # cd htmldir 152 # sh example_create.sh 153 </div> 154 <p>Your static stagit website should be generated for you! Check by going to git.yourdomain.com. 155 156 <hr> 157 158 <li>3) Next you want to set up ownership, links, and descriptions for stagiit to display</li> 159 <div class="code-box"> 160 <h3>Descriptions</h3> 161 <p># This is my git repo > /srv/git/yourrepo.git/description</p> 162 </div> 163 164 <div class="code-box"> 165 <h3>URL</h3> 166 <p># git://yourdomain.com/yourrepo.git > /srv/git/yourrepo.git/url 167 </div> 168 169 <div class="code-box"> 170 <h3>Owner</h3> 171 <p># owner > /srv/git/yourrepo.git/owner</p> 172 </div> 173 174 <div class="code-box"> 175 <h3>Update stagit</h3> 176 <p># sh /var/www/git/htmldir/example_create.sh</p> 177 </div> 178 179 <p>Now repete for all of your repos till all is correct!</p> 180 181 <hr> 182 <li>3) Now you want it so stagit updates whenever there is an update, thankfully for you I have modified the script to work whenever a git commit is made!</li> 183 <div class="code-box"> 184 # cp /var/www/git/example_post-receive.sh /srv/git /srv/git/yourgitrepo.git/hooks/post-receive 185 </div> 186 <p>Now whenever you push a commit everything should update!</p><hr> 187 188 <h1>Overview</h1> 189 <p>I hope this guide has helped you setup a kool git server! If there are any problems please contact me!</p> 190 191 <center> 192 <hr> 193 <pre text-align=center> <a href="../../linuxlist.html">Back 🚪</a> 194 </main> 195 </body> 196 </html> 197