
Creating Your Own Git Server - gpanders
https://gpanders.com/posts/creating-your-own-git-server/
======
wahern
Git supports read-only, static HTTP cloning using nothing but "GET" requests
on a bare Git repository. IOW, you don't need a CGI program or special request
processor to serve a Git repository over HTTP. All you need to do is 1) make
the bare Git repository visible under your web server's document root the same
as-if you were serving .gif or .js files, and 2) maintain a special index
after every commit using `git --bare update-server-info`, which I invoke from
a post-receive hook.[1]

Because of this, you don't even need a CGI program for a web UI.
Theoretically, it could all be done from client-side JavaScript. I've been
wanting to write a PoC, but it's deep in my side-project backlog.

Why bother? Because a read-only, static Git mirror is more secure--there's no
server software (other than a basic web server) that can be exploited. And
nothing is always easier to maintain than something.

You still need SSH (or a git:// daemon) for write access, unless the entire
environment is just for read-only cloning. But SSH access is presumably
something already setup and used by the core contributors. (Probably shell
access, too, but SSH logins can always be forced to invoke git.)

IMO, static, read-only HTTP cloning is a killer feature of Git which AFAIK
cannot be matched by CVS, Subversion, Mercurial, or Fossil, at least not out-
of-the-box.

[1] From a hook on the read-write, master repository outside the web server
sandbox.

~~~
t0astbread
Something that would be a bit difficult when you only wanna use static files
is code search. Would you need a backend for that or am I missing some obvious
solution?

~~~
lordalch
Once you clone the repository, you can search locally using Git Grep, Git ls-
tree, etc.

~~~
t0astbread
Of course but that could be inconvenient in some situations. Like, when you
just wanna show someone something in your code or when you wanna search across
all repositories but don't wanna clone every single one manually again.

------
durandal1
I recently set up Gitea on a VPS for my personal projects - I can highly
recommend it. Setup was easy (for someone comfortable with linux configuration
basics) and it's been an awesome improvement to my hobby development flow.

~~~
lucb1e
Seconded. I setup gitea on my server when Microsoft bought GitHub after
comparing between gitlab, bitbucket, gogs, cgit, gitolite, and gitea. Gitea
has the best community, features, and system requirements. Sad to say I still
haven't moved my projects off of GitHub, but gitea setup wasn't the problem.

One thing I'd still like to see, and am thinking if I may (as a nobody with no
connections) somehow be able to organise myself, is a global search. One of
the main advantages of GitHub is discoverability, both as a project owner and
as a project seeker. What if there was a server that distributed searches to
the different self-hosted instances of gitea/gogs/gitlab/etc.? (Opt-in of
course.)

The search would be distributed amongst all those setups which hopefully makes
it light enough even though there will probably be a large volume, and this
way people would have no reason to stay with a centralized company for git and
bugtracker hosting. You could even have a client that connects to the
instances individually, so even the search distribution server does not have
to be centralized, you just need a DHT (ahem, I mean _blockchain_!) or some
other central list of contributing nodes. And for very lightweight setups that
still want to appear in search results, one could perhaps have different
levels of results, from full code index to repository names and descriptions
only.

~~~
oever
You can get support for implementing something like this from NLnet. Either a
federated version or a 'google for git' would fit the bill I imagine.

Or adding a code search feature to Software Heritage.

[https://nlnet.nl/discovery/](https://nlnet.nl/discovery/)

~~~
lucb1e
That's a very interesting idea!

Edit: removed a part about ForgeFed which I thought was what I had in mind,
and they do a lot of things that would be nice to have (slightly more
convenient than just "login with GitHub")... except search which you can't
simply work around by creating an account on each git server where you want to
contribute. Not sure what part of their project is discovery and why NLnet
granted them money under the "Next Generation Search and Discovery" fund
which, from the description, is very clearly aimed at search.

------
andolanra
I now use a personal Gogs instance, but I also want to give a shout-out to
Klaus: it's something like Gitweb with a more Github-like UI. Klaus (like
Github) shows you first and foremost the state of the tree with nicely
rendered or syntax-highlighted file contents instead of (like Gitweb) focusing
on the commit history first. It also has smart Git HTTP support out of the box
without having to muck around in the web server config as described in this
post.

The project is here
[https://github.com/jonashaag/klaus](https://github.com/jonashaag/klaus) and
you can see a preview of it here:
[http://klausdemo.lophus.org/](http://klausdemo.lophus.org/)

------
monksy
I've installed Gitlab in the earlier days, and that seems a lot easer than
this guide. Gitlab comes with the web view included.

~~~
cuspycode
I agree with that. I did investigate a number of self-hosted alternatives to
Github, but Gitlab was so much easier than any of them. My only complaint
about Gitlab is that it uses a lot of CPU even when completely idle. But I was
able to fix that easily by throttling it via the "cpulimit" utility.

My Fossil server on the other hand, has had no problems at all. Unless your
project requires Git, you could save some pain by considering Fossil instead
of Git.

------
velcrovan
You can also set up your own Fossil server by downloading a single executable
and running it with a 2-line CGI script. Includes issues, wiki and forum.

[https://www.fossil-scm.org/home/doc/trunk/www/server/](https://www.fossil-
scm.org/home/doc/trunk/www/server/)

~~~
deft
This is making me think about switching from gitlab. I don't like how
complicated it is and it has way more features than I'll ever need. But I
don't know how to use fossil. How does a git user become a fossil user and is
it worth it just to switch webservers?

~~~
velcrovan
Late reply but...

> How does a git user become a fossil user

You just need to download the binary and start trying it out. Check out the
Quick Start: [https://fossil-
scm.org/home/doc/trunk/www/quickstart.wiki](https://fossil-
scm.org/home/doc/trunk/www/quickstart.wiki)

A couple quick notes to help smooth the learning curve:

\- There is no “staging” step in Fossil. Doing fossil commit immediately
commits all changes in all tracked files into the repository. If you need to,
you can specify which file or files you want to be included in the commit.

\- There is no selective “patch committing” in Fossil (i.e., git add -p in
Git), reportedly because it facilitates check-ins of untested code. So, if
you’re in the habit of making unrelated edits to code…stop it!

> is it worth it just to switch webservers?

Depends on your priorities for each affected project. I already maintain a VPS
as a web server for my various websites, so putting Fossil on it was an easy
step. There is also Chiselapp.com if you don’t want to maintain your own web
server.

There is also the fact that it’s just not git. Unless your project is
extremely popular, you aren’t going to be getting “drive by pull requests”
from anyone. The bar for participation in your project is going to be much
higher since most people just aren’t familiar with Fossil. Depending on the
project this could be a good thing or a bad thing.

------
grayed-down
This is a very good write up. I've set up countless git servers in the day and
have never really had the need for a UI, but I am intrigued by the description
of gitweb.

On that note however, I would encourage anyone with a passing interest in an
scm gui to check out fossil-scm. I'm helping a colleague with a project and
that's what he is using. Really incredible piece of software with a lot of
possibilities.

~~~
gpanders
You're the third person in this comment section to mention Fossil. I'd never
heard of it, but I'm definitely going to check it out.

------
daneel_w
I'm tremendously happy with Gitea - [https://gitea.io/](https://gitea.io/) \-
which in my opinion gets you as close as you can come to your own self-hosted
version of GitHub, installed and ready to use in just minutes.

------
Havoc
I did set up my own gitlab on a VPS. That ended up feeling quite fragile
thought tbh. Even a working deploy (docker) seems to be spitting out a fair
number of warnings. Jikes.

So new plan is google source repo + mirror somewhere safe for backup / non-
google backup

------
emrahcom
I frequently install Gitea on Debian. Therefore I prepared an installer to do
it:

[https://github.com/emrahcom/emrah-buster-templates#eb-
gitea](https://github.com/emrahcom/emrah-buster-templates#eb-gitea)

------
p0d
gitlab-ce is an apt install/upgrade and works like a charm.

I have a dual-core duo box running about 6 containers, including gitlab, and
nginx as a reverse proxy.

I use letsencrypt for ssl, basic auth and duckdns to point cnames to my dhcp
DSL.

I've been running my dev environment like this for several years. Works great.

------
aquir
you can also host your own Gitlab...

