
Shit – An implementation of Git using POSIX shell - kick
https://git.sr.ht/~sircmpwn/shit
======
ddevault
Hiya HN. I was ranting on Mastodon earlier today because I feel like people
learn git the wrong way - from the outside in, instead of the inside out. I
reasoned that git internals are pretty simple and easy to understand, and that
the supposedly obtuse interface makes a lot more sense when you approach it
with an understanding of the fundamentals in hand. I said that the internals
were so simple that you could implement a workable version of git using only
shell scripts inside of an afternoon. So I wrapped up what I was working on
and set out to prove it.

Five hours later, it had turned into less of a simple explanation of "look how
simple these primitives are, we can create them with only a dozen lines of
shell scripting!" and more into "oh fuck, I didn't realize that the git index
is a binary file format". Then it became a personal challenge to try and make
it work anyway, despite POSIX shell scripts clearly being totally unsuitable
for manipulating that kind of data.

Anyway, this is awful, don't use it for anything, don't read the code, don't
look at it, just don't.

~~~
wkjagt
> instead of the inside out

Now the name makes even more sense. I first read it as sh/git, but reading it
as something that starts inside and slowly works its way out is now my
preferred explanation of the name.

~~~
sbergot
The name also plays well with the porcelain & plumbing metaphores of git.

~~~
hyperpallium
metaphors. Not being pedantic, it just puzzled me a while to see what was
wrong with that word.

~~~
fouc
what do you get when you cross a metaphor and a semaphore? a metaphore

~~~
maw
I never sem a phore that I didn't like.

¿

~~~
brian_herman__
lol

------
kick
This was done in the span of a few hours, and was committed to sr.ht using
itself.

Drew even livestreamed the whole thing, but I don't think he's uploaded it to
a PeerTube instance yet.

~~~
orf
Where was it livestreamed?

~~~
kick
He has a subdomain on his site that he uses for it:

[https://live.drewdevault.com/](https://live.drewdevault.com/)

~~~
danShumway
You're not the right person to ask about this, but if Drew is around I would
_love_ to hear high-level details about what how this setup works and what the
average monthly cost is.

I can see that it's open source[0], and I'm very tempted to copy it. I'm
already in the midst of migrating all of my video hosting to peertube, but I
don't have a solution I'm confident in for livestreaming other than Twitch --
especially because when in the rare instances where I do stream coding
sessions they can go up to 5 or 6 hours, at which point archiving and storing
that video starts to look a lot more costly.

[0]:
[https://git.sr.ht/~sircmpwn/live.drewdevault.com/tree](https://git.sr.ht/~sircmpwn/live.drewdevault.com/tree)

~~~
ddevault
I don't use it very often. I just threw it up on a Linode with minimal effort
so I could have a working live streaming setup. You'll note from the readme:

>This is the website for my self-hosted livestreaming platform (aka bag of
hacks dumped into a server).

PeerTube is nice in theory but in practice it's been really really unreliable
for me.

~~~
alpb
Why not simply stream to somewhere live Twitch/YouTube and have them serve the
recording offline later on?

~~~
ddevault
I try to avoid proprietary services.

~~~
munificent
You know, YouTube is pretty easy. I bet someone could implement it in an
afternoon and a dozen lines of shell script...

~~~
csunbird
Is this a challenge?

------
iamEAP
I once landed a job as a web developer in a marketing department where IT was
gatekeeping production hard.

Although all the code was in git (the real git), deployment involved a magical
shell script someone in IT had written ages ago. Only after a bunch of rocky,
outage-causing deployments did we have the sense to start digging into this
magic script.

It turned out it was just a bad, thousands of lines long re-implementation of
git using perl and mysql that captured and stored diffs and rsync'd them to
production. ...And this was well into the era of CI/CD and infrastructure
automation tools.

Eventually, the company brought in new IT leadership that put an end to that
kind of nonsense, which freed us in marketing to buy purpose-built PaaS for
our needs.

Obviously do this kind of crazy stuff as you please on the side. But at work,
build only what uniquely adds value to your company. For most, dev tools are
probably pretty low on that list.

~~~
angry_octet
I really disagree, a small amount of customisation of tools can reap
significant productivity gains.

I think your anecdote is really just an example of bad management, not bad
tooling. Could easily be that some management doofus had prohibited git from
being installed on the 'production' system.

~~~
peterwwillis
I think the problem is the idea of 'tooling'.

A table saw by itself is mostly useless. With a fence and a miter gauge, it
becomes useful. With a push block, stop block, subfence, outfeed table, infeed
table, featherboard, crosscut sled, tenon jig, and dado set, it is the single
most useful tool in a woodshop. Keep in mind it is still _one tool_ and all
those accessories are not "tooling", they are accessories to a single tool
that increase what you can do with it. The tool always works the same way, and
anyone can use it with any of those accessories in any woodshop in the world.
In effect it becomes a new, larger solution, made up of many features that
extend the utility of the tool.

That's not really what we have. Mostly what we have are jigs. A jig isn't an
outfeed table or a crosscut sled. It's a hack for a particular job. If you
need to make one specific cut 300 times, you nail together some scrap wood,
dial in the miter gauge, angle the saw blade, and make your cuts. And the jig
is scrap once again.

But in the heady new world of "DevOps engineering", the jig is now "tooling",
and we pat ourselves on the back that we were able to nail some scrap wood
together and claim it created business value. Of course, it's not a _shitty_
jig like in the bad old days of shell scripts ("ha ha! remember when we were
productive with this simple code that was portable and not gigantic or
complicated? how foolish!"), because instead of making it out of scrap wood,
we now make it out of scrap steel with a MIG welder. We're _advanced_ now.

And I'll go further. The fact that most woodworkers make their own tablesaw
extensions is illustrative of the problem: craftspeople like having fun with
their toys. Is there value and experience and dollar savings you get out of
making your own crosscut sled? Sure! But it'll also take you 1-2 days of
buying parts, measuring, cutting, gluing, clamping, drying, aligning, and
finishing. Any business with any sense should have paid $100 to just buy a
complete crosscut sled made of aluminum with a good design that will last
forever. But they are too dumb to notice they're spending an inordinate amount
of time and money on craftspeople making jigs.

I wish the ghost of W. Edwards Deming would rise from the grave and call us
what we are: bullshit artists.

~~~
ivix
I think you're saying that "creating home made tooling is a waste of time, and
you should just use professional tools"?

In which case I agree, for almost all cases. A carpenter trying to build their
own saw or chisel would be laughed out of the workshop, and rightly so.

However, the mark of a master craftsman is one who can identify when custom
tooling are necessary and knows something about how to build them.

~~~
_carl_jung
In my opinion, this is simply an over-extended metaphor. Programming
ultimately is not carpentry, and custom tooling is justifiable in many more
cases.

------
ac42
I wasn't aware of the plumbing / porcelain metaphor in git until now.

It's fantastic to what lengths some of us go for a good pun :-)

------
singingfish
There are two hard problems in computer science:

1\. Cache invalidation. 2\. Naming things 3\. Off by one errors.

This person has #2 nailed down, hard.

------
downerending
Amusing, but less than the title suggests (no porcelain, no reliability
properties, no error checking, etc).

Still, fun stuff.

~~~
jaytaylor
Interesting terminology, I'd never heard of porcelain in the context of git.

In case there are others like me, this will save some clicking:

[https://stackoverflow.com/q/6976473/293064](https://stackoverflow.com/q/6976473/293064)

~~~
Sean1708
Am I reading that correctly? A porcelain command is one that's _not_ supposed
to be used in scripts, but the --porcelain flag is for when you _do_ want to
use things in scripts?

------
ReverseCold
I initially thought it was "SourceHut gIT" not "SHell gIT"

I don't mean any offense by that - sourcehut is fine - just what popped into
my head.

------
mkirch
It seems that the logical next step after the birth of this monstrosity would
be to create the next best platform: ShitHub

------
J5892
This is great, but I already use "shit" as an alias for "fuck".

~~~
sjwright
If there's anything you don't want to confuse, it's your shit and your fuck.
Keep them separate, people. Keep them separate.

~~~
h2odragon
The world is big enough for everyone's kinks; I'll keep mine off yours and you
return the favor tx

~~~
sjwright
You can have whatever kinks you want, but you can't escape the germ theory of
disease.

------
mar77i
[https://wyag.thb.lt/](https://wyag.thb.lt/) If you want to hop the same
train, I saw this long ago...

------
awkward
So if this is the git internals, shit is what goes inside the porcelain
plumbing?

------
billconan
are there any other implementations in other languages? (preferably c++).

I use libgit2, but the code is a bit difficult to read and hack. I know there
is a ruby book implementing from scratch.

I want to understand the git internals.

~~~
kbumsik
Let's rewrite everything in JavaScript:

[https://github.com/isomorphic-git/isomorphic-
git](https://github.com/isomorphic-git/isomorphic-git)

~~~
K0SM0S
What a strange way to spell Rust:

[https://news.ycombinator.com/item?id=19540845](https://news.ycombinator.com/item?id=19540845)

(to GP: lots of links related to reimplementing git in there)

------
Koshkin
Isn't this how Git was originally done?

~~~
cesarb
No, git was originally done in C:
[https://git.kernel.org/pub/scm/git/git.git/commit/?id=e83c51...](https://git.kernel.org/pub/scm/git/git.git/commit/?id=e83c5163316f89bfbde7d9ab23ca2e25604af290)

~~~
raphlinus
It's slightly more complicated than that. The `git` command line itself was
done in shell. Initially, `git foo` just ran `git-foo-script`, and then those
were also written in shell. But the actual sha1 and packfile stuff was always
in C from the beginning.

Source:
[https://git.kernel.org/pub/scm/git/git.git/commit/git?h=v0.9...](https://git.kernel.org/pub/scm/git/git.git/commit/git?h=v0.99&id=e764b8e8b3c50b131be825532ba26fa346d6586e)

------
chungy
Impressive! Though very lacking on any kind of instructional use. "init" is
easy enough to figure out, but there's no "add" step. Shame :)

~~~
ddevault
Sorry, I wasn't expecting this to HN before I had written some porcelain
commands. I pushed an updated README that explains how to write commits with
this.

------
_bxg1
10/10 on wordplay

~~~
steelframe
It's cute, but it negatively impacts my ability to effectively advocate for
the tool in my workplace.

~~~
viraptor
So... That's a very good choice of name then. You shouldn't advocate for it.

------
srathi
This is essentially adding a blob inside .git/objects by taking a sha1 hash of
the data after appending a header "blog <length>\00<data>". Then the first two
characters of the hash are created as a directory and the remaining 38 acts as
the file name inside which the zlib compressed data is stored. Nice project
for learning the git internals.

~~~
ddevault
Well, it also includes creating tree and commit objects, and reading and
writing the git index.

~~~
srathi
Yes, of course. I was mainly stating the starting point.

------
m3kw9
Try and market this shit

------
harry8
"Shellgrit" which I've heard used to recover from starting to say "shit" in
circumstances where that isn't appropriate.

Better name and contraction of "shell git" ? Or maybe this is not something in
common usage. Dunno.

------
daniel-dev
i like the name so that's why i read it

------
megavolcano
wasn't the original version of git mostly entirely shell scripts?

------
noypi3
that means i can put shit on my busybox.

------
pmarreck
I feel like the name was conceived before the tool in this case. Also,
hilarious.

------
quotemstr
I don't think anybody should be targeting plain POSIX shell anymore. There are
much richer shells available almost everywhere.

------
m0zg
Unfortunately "rt" TLD is not a thing. Otherwise it'd be worthwhile to
register sh.rt as an alternate domain for sr.ht.

------
bigyanshr
What's wrong with people nowadays? Couldn't they come with a better name ?

~~~
cannam
Git is already an insulting term where I come from - I remember one of our
children, years ago when they were young, looking at my screen and saying "why
are you typing _git_ ??" in a shocked sort of tone.

They're much less concerned about their language now.

I don't mean to overstate the case - it's not a swearword or the sort of thing
you'd really censor, just a playground term for a mean person. All the same
it's an ugly word and (however irrationally) this is one of the reasons I
prefer Mercurial to this day.

~~~
krallja
Mercurial is also an insult. Both projects were started in response to a
mercurial git’s actions.

