
Build Git – Learn Git - chinchang
http://kushagragour.in/blog/2014/01/build-git-learn-git/
======
unwind
This is nice. One pet peeve is that (as far as I know, I'm really not an
expert) Git repos don't actually have names. The first thing the article does
when implementing them is to give them names, which I thought was a bit
jarring.

I actually think the namelessness of the repos is one of the things that are
unexpectedly cool about Git.

~~~
chinchang
Probably right.I think I gave them naming keeping mind Github repos have
name...maybe :)

~~~
pedalpete
I always thought that was just the name of the parent folder of .git

~~~
unfunco
That's correct, repositories themselves are not named. You can change the name
of the parent directory without consequence.

~~~
shurcooL
Renaming more things should be this easy.

------
Cogito
I appreciate the work that has gone into this, and think it is a great
starting point for an interesting tutorial about git.

My concern is that the tutorial ignores or discards ideas essential to how git
works, and what makes git different to other version control systems.

As other comments have said, this is showing 'just another SCM system' without
illuminating the design decisions that make git different.

For example, in git it is extremely important that commit objects have a
unique identifier for any given working directory, history, and commit meta-
data. Without this guarantee the distributed architecture of git is (almost)
impossible to implement.

In the commit section the tutorial states:

 _a simple Commit class would have ... a change containing the snapshot of
change made. Understanding how a change is actually stored is beyond the scope
of this implementation._

This terminology is misleading at best, and skips over a very important
concept in how git actually works. The phrase 'snapshot of change made' is
misleading, as a commit doesn't contain any explicit information about changes
made. Instead, the staged files in the working directory are saved into a
'blob' store, a tree structure is created to represent the directory
structure, and a reference to the tree is saved in the commit object. I
understand that all this is outside the scope of the tutorial, however an
outline of how commits work is important information for anyone trying to
understand how git works. For example, the storage format is the primary
reason operations in git are so fast.

Again, I like the tutorial, but if it wants to teach about git, as opposed to
other version control systems, it needs to ensure the key git concepts are
maintained.

~~~
chromejs10
I 100% agree. It's always great to try to implement complicated things, but it
misses the point if what you're implementing is nothing like the original
system. You aren't learning how Git works if you do it that way are instead
just mimicking API names

~~~
chinchang
Reiterating on my point again, the aim of this project is not to replicate
Git. JS-Git ([https://github.com/creationix/js-
git](https://github.com/creationix/js-git)) does that.Here I am trying to code
basic concepts relaxing complex stuff so that reader can focus & visualize
more abstract concepts. I have tried to bring in concepts as and when wanted
instead of just overloading the reader with complex stuff all at once.

~~~
chromejs10
Which is fine. But you're specifically saying that you are building Git to
learn how it works. All I'm saying is, based on your wording, you need a
disclaimer that this is not how Git works internally. You can already get the
gist from a lot of the comments that they think they now know how Git works
after reading this post.

I appreciate the effort and think it's a great idea to implement something
your own way, I'm just trying to point out that you're saying this is how THE
Git works, which it isn't. Nice write up as a whole though

------
drrotmos
A nice concept, but it doesn't _really_ have much to do with Git. It's just
another SCM system, and the concepts are just as applicable to e.g. Mercurial
as Git. There are enough differences from Git to make it quite incompatible
(named repository, incremented commit IDs, single parents et c.).

~~~
chinchang
The point is to implement gradually. For example, in the concepts covered in
part 1, multiple parents was not required, hence it was left. It should make
sense to the reader why something was implemented and why it does what it
does.

Its concepts might apply to other VCS. But that is immaterial, Git is what we
are trying to understand here.

------
graywh
This reminds me of a talk by Jim Wierich I heard years ago where he pretends
to design a new vcs in order to explain how git works.

I'm not sure if a full recording can be found anywhere other than buying it
from Pragmatic Programmers.
[https://www.youtube.com/watch?v=bBQJP6D8aGY](https://www.youtube.com/watch?v=bBQJP6D8aGY)

~~~
jimweirich
The talk is only available as a screencast from the Pragmatic Programmers, but
the slides are freely available on my github account
([https://github.com/jimweirich/presentation_source_control](https://github.com/jimweirich/presentation_source_control)).

I use this talk as an introduction to any Git Immersion workshops that I run
(see also [http://gitimmersion.com/](http://gitimmersion.com/))

------
jbranchaud
Tutorial looks awesome. It would be helpful if you would mention from the
beginning that you will be implementing in JavaScript before reaching the code
snippets.

~~~
chinchang
Valid point. Will update the article. Thanks.

------
evmar
I also attempted to understand git better by implementing it, but my (Haskell,
uncompleted, abandonded) implementation was more concerned with getting all
the on-disk representations right: [http://evan-
tech.livejournal.com/254793.html](http://evan-
tech.livejournal.com/254793.html)

------
Crito
A related good way of learning Git is to check out/checkout the very first
commits of git made using git. I found the shear lack of code that a working
system could be made of to be enlightening.

------
jonhmchan
This is an excellent resource. On Bento, I have so many tutorials and
walkthroughs on the basics of Git (it's a very readily accessible teaching
opportunity) that it's gotten somewhat unwieldy. In many instances, some of
the material is very base, and I've been looking for something more thorough
without being too specialized.

This gives an excellent walkthrough of how Git works, but not only that,
serves an excellent exercise on JavaScript. Bravo.

------
codez
It's a cool concept but like other comments say it overlooks a lot of the
things that make git, git.

Best way to learn? use it!

Maybe just create a dummy repo and go from there with it. Maybe use the GUI
tools until you're comfortable with the command line.

For me personally, it was command line first. If you aren't sure about
something with git, googling it will pretty much always throw out your answer.

~~~
andrewaylett
I'm not sure I quite agree. Use it, yes, but if you're using Git as a black
box then you're much more likely to be frustrated by it than if you understand
what's going on under the hood. I tend to point people at "Git from the bottom
up"[0] -- it gives people the understanding they need to work out the effect
they require, from which they can work out which set of commands will get them
there.

[0]
[http://ftp.newartisans.com/pub/git.from.bottom.up.pdf](http://ftp.newartisans.com/pub/git.from.bottom.up.pdf)

~~~
codez
Most people will not be using advanced functions though and if people
generally understand how version control works, I don't think git is super
hard to pick up and learning whilst doing is most effective for me.

I'm sure most people are probably aware of :
[http://try.github.io/](http://try.github.io/)

which is a cool little resource for learning git.

------
grabeh
I suspect you may already be aware, but if not then here's a related project
[https://github.com/creationix/js-git](https://github.com/creationix/js-git).

Lest you misunderstand, I'm not saying you should stop development, I just
thought it might be of interest!

~~~
masklinn
Or, in a different language,
[https://github.com/jelmer/dulwich](https://github.com/jelmer/dulwich)

------
together_us
I love the idea! This is a really cool way to learn anything, then, for that
matter, I guess. Thank you.

~~~
traviscj
BINGO. I actually try to do this before job interviews: build a dumb version
of one of their big products. I'm not even talking about something as
sophisticated as this git project, I mean "build a dumb version".

------
rajeshpillai
Great work and keep continuing with the series. I understand this is not
exactly the real git's inner working, but this series of articles may lead
some other coder or hacker or other inquisitive mind to stitch together the
missing part. That's the beauty of sharing!

------
esteb_li
Very nice. Basic reimplementation is always useful to visualize abstract
concept like Git. Git can be hard to new comers, as it's not always obvious
what commit/branch/push does. Thank you

------
twice
Thank you, it's a very nice tutorial and I have not thought about this before
(concept of trying to implement something you want to learn and get a better
understanding of).

------
joelgrus
This is a great way to understand Git, thanks!

------
bhaisaab
Great post by an awesome humble programmer :)

(NB: he's a friend who also happens to be a colleague at work)

~~~
eklavya
nice nick Bhaiji :P

------
holoiii
Very cool. I would like to see other utilities or tools explained in this way.

Keep up the good work!

------
talles
Sweet. Should have take quite some time to format the whole tutorial.

~~~
chinchang
It sure did. Though, there is a lot of code, so its always fun :)

------
jheriko
implementing git is an interesting approach to learning it.

i generally support this kind of stuff - however I think that this starts out
implementing a source control solution rather than git in particular and its a
shame that it follows git so closely later down the line in that regard (but
completely understandable given the aim).

solving the problems for yourself you can get some insight into why git is the
way it is (and svn, p4, hg, everyone else...)

~~~
ahuth
I'm pretty sure the point of the article is to learn about how to use git by
implementing its basic functionality. The point isn't to implement how git
works.

On a side note, I'm always amazed when someone implements things that are
complicated to me in a really understandable ways.

------
vaidik
Awesome work as always chinchang!

------
xrd
Brilliantly done. Thank you.

------
pkmishra
Really cool. I loved it.

