{"id":15035939,"url":"https://github.com/kbilsted/kbgit","last_synced_at":"2025-06-16T13:09:14.236Z","repository":{"id":69160148,"uuid":"124583204","full_name":"kbilsted/KBGit","owner":"kbilsted","description":"Git implemented from the ground in 500 lines of code (or less)...","archived":false,"fork":false,"pushed_at":"2020-07-28T13:48:57.000Z","size":107,"stargazers_count":20,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T01:11:25.813Z","etag":null,"topics":["csharp-code","git"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kbilsted.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-09T19:17:50.000Z","updated_at":"2022-06-03T01:13:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"cc38b703-46d3-4679-a0e6-ed6c321d757c","html_url":"https://github.com/kbilsted/KBGit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbilsted%2FKBGit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbilsted%2FKBGit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbilsted%2FKBGit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbilsted%2FKBGit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kbilsted","download_url":"https://codeload.github.com/kbilsted/KBGit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126287,"owners_count":21051896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp-code","git"],"created_at":"2024-09-24T20:29:48.105Z","updated_at":"2025-04-09T23:20:48.620Z","avatar_url":"https://github.com/kbilsted.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KBGit - Git implemented from scratch in 500 lines of code (or less ...)\r\n\r\nProject statistics:  \u003c!--start--\u003e\r\n[![Stats](https://img.shields.io/badge/Code_lines-382-ff69b4.svg)]()\r\n[![Stats](https://img.shields.io/badge/Doc_lines-25-ff69b4.svg)]()\r\n\u003c!--end--\u003e\r\n\r\nRecently I dug into their implementation details of Git. The simplicity of the implementation was completely mind-boggling. \r\nWhat a gem I found! Such a simple model for something conceptually complex as a source code versioning system. I almost couldn't believe it!\r\n\r\nI wanted to share the beauty of the details of Git's inner workings. So how to best do this? \r\nI found inspiration from Terry A. Davis' work on [TempleOS](http://www.templeos.org)\r\n\r\n\u003e\tEverybody is obsessed, Jedi mind-tricked, by the notion that when you scale-up, \r\n\u003e\tit doesn't get bad, it gets worse.  They automatically think things are going to \r\n\u003e\tget bigger.  Guess what happens when you scale down?  It doesn't get good, it \r\n\u003e\tgets better!\r\n\u003e\t-- Terry A. Davis (https://templeos.sheikhs.space/Wb/Doc/Strategy.html)\r\n\r\nSo why would you want to grok this code? The reward reaped is that you'll find many of the operations of Git much more natural. They will suddenly make sense.\r\nIn order to have a fighting chance of conveying anything to any reader (and as Terry says). Less is more. **I challenged myself to keep the implementation \r\nto a maximum of 500 lines of code.. for a \"complete re-implementation of git\"!**\r\n\r\nI want a fair game, though. And 500 lines of code is not a lot. To prevent myself from spiraling into an code-obfuscation contest in order to save \r\na few lines of code, I'm counting lines using a [simple line counting library](https://github.com/kbilsted/LineCounter.Net) \r\nwhich count only semantic lines (i.e. exclude empty lines, lines only containing `{`, `}`,...). \r\n\r\nKBGit..what?? My initials are *K.B.G.* - hence the name KBGit :-)\r\n\r\n## Features implemented\r\n\r\n * commits\r\n * branches \r\n   * (create, list, delete)\r\n   * detached heads\r\n   * HEAD branch\r\n * checkout branches or commits\r\n * logging\r\n * push + pull\r\n * clone\r\n * remote (create, list, delete)\r\n * command line parser\r\n * store git state on disk \r\n\r\n\r\n## Planned work \r\n\t\r\n * git log \r\n   * graphical (--graph)\r\n   * patch (-p)\r\n   * \"less\" implementation\r\n * git INDEX rather than scanning files\r\n * blob compression\r\n * diff'er to show changes to files \r\n   * and select changes to index...\r\n \r\n\r\nI will blog about the implementation on [http://firstclassthoughts.co.uk/](http://firstclassthoughts.co.uk/) \r\nwhen the implementation has stabilized. Comments etc. are much welcommed.\r\n\r\nFor now the reading guide is to just read the `Git.cs` file. The main classes are the `CommandLineHandling` which is the facade of the implementation. \r\nThe first class `KBGit` holds or redirects the main functionalities of Git. For now, just browse around with outset in those classes.\r\n\r\nArticles\r\n  * Command line parsing: [http://firstclassthoughts.co.uk/Articles/Readability/PreferDeclarativeCodeOverImperativeCode.html](http://firstclassthoughts.co.uk/Articles/Readability/PreferDeclarativeCodeOverImperativeCode.html)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbilsted%2Fkbgit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkbilsted%2Fkbgit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbilsted%2Fkbgit/lists"}