Add info about git hosting, and gitweb

master
Nathan Steel 5 years ago
parent 705370f43f
commit 8747f62cf8

@ -0,0 +1,56 @@
# Git Server
`su -` Switch to root for most of this
## Make a git user
`adduser git`
Adduser if prefered to useradd, but in case
`useradd git`
`mkdir /home/git`
`chown -R git:git /home/git`
## Make the git directory
`mkdir /srv/git` This can got anywhere, but this makes sense
`cd /srv/git`
### Give ownership of the directory
`chown -R git:git /srv/git`
## Add a repo
`git init --bare <repo>`
## How to clone, commit, etc. from your server
### Add existing branch
Add remote to existing Repo
`git init`
`git remote add <origin> ssh://git@<host>:<port>/srv/git/<repo>` \*
`git push (--set-upstream/-u) <origin> <branch>`
### \* Remove the port
Don't use the <port>! You don't need to if your port is 22 (default ssh).
If you've changed it to be more secure, then instead change your ssh config!!
`.ssh/config` add
Host <host>
Port <port>
### Clone the branch
Clone is the same, but with `git clone`, not `git remote add <origin>`
## Add SSH keys
As the git user!
`su git` if you're still logged in as root :)
Either ssh-copy-id from your PC, connecting to the server as git@<server>.
Or
Make an authorised keys file and add keys manually
`mkdir .ssh && chmod 700 .ssh`
`touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys`
Then copy keys into `.ssh/authorized_keys`

@ -0,0 +1,51 @@
# GitWeb
A web GUI for your repositories
This is assuming an install of git, and nginx
## Install gitweb
Debian already has this as a package.
If your server distro doesn't...
`sudo apt install gitweb fcgiwrap`
## Setup a webpage
### Create a new nginx site
`vim /etc/nginx/sites-available/gitweb`
Add the following
`server {
listen 80 ;
listen [::]:80 ;
server_name git.<domain> www.git.<domain> ;
location /index.cgi {
root /usr/share/gitweb/;
include fastcgi_params;
gzip off;
fastcgi_param SCRIPT_NAME $uri;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location / {
root /usr/share/gitweb/;
index index.cgi;
}
}`
#### Copy new site to site-enables
`ln -s /etc/nginx/sites-available/gitweb /etc/nginx/sites-enabled/`
### Change default gitweb location
`vim /etc/gitweb.conf`
Amend the line containing `/var/lib/git` to `/srv/git`
Reload nginx
`systemctl reload nginx`

@ -0,0 +1,72 @@
# https://stackoverflow.com/questions/6414227/how-to-serve-git-through-http-via-nginx-with-user-password/17553364#answer-17553364
server {
listen 80 ;
listen [::]:80 ;
if ($host = git.aney.co.uk) {
return 301 https://$host$request_uri ;
}
if ($host = www.git.aney.co.uk) {
return 301 https://$host$request_uri ;
}
return 404;
}
server {
listen 443 ssl;
listen [::]:443;
server_name git.aney.co.uk ;
root /usr/share/gitweb/;
# Remove auth_* if you don't want HTTP Basic Auth
#auth_basic "example Git";
#auth_basic_user_file /etc/nginx/.htpasswd;
# static repo files for cloning over https
location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
root /srv/git/;
}
# requests that need to go to git-http-backend
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
root /srv/git/;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param PATH_INFO $uri;
fastcgi_param GIT_PROJECT_ROOT $document_root;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param REMOTE_USER $remote_user;
include fastcgi_params;
}
# Remove all conf beyond if you don't want Gitweb
try_files $uri @gitweb;
location @gitweb {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/gitweb.cgi;
fastcgi_param PATH_INFO $uri;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
include fastcgi_params;
}
#location /index.cgi {
#root /usr/share/gitweb/;
#include fastcgi_params;
#gzip off;
#fastcgi_param SCRIPT_NAME $uri;
#fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
#fastcgi_pass unix:/var/run/fcgiwrap.socket;
#}
#location / {
#root /usr/share/gitweb/;
#index index.cgi;
#}
ssl_certificate /etc/letsencrypt/live/git.aney.co.uk/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/git.aney.co.uk/privkey.pem; # managed by Certbot
}
Loading…
Cancel
Save