{"id":16718217,"url":"https://github.com/allouis/git-internals","last_synced_at":"2026-02-02T11:01:38.342Z","repository":{"id":28507225,"uuid":"32023746","full_name":"allouis/git-internals","owner":"allouis","description":null,"archived":false,"fork":false,"pushed_at":"2015-03-11T17:23:19.000Z","size":142,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"gh-pages","last_synced_at":"2025-03-15T10:13:19.175Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allouis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-11T15:00:18.000Z","updated_at":"2015-03-11T17:23:19.000Z","dependencies_parsed_at":"2022-09-03T14:42:37.815Z","dependency_job_id":null,"html_url":"https://github.com/allouis/git-internals","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/allouis/git-internals","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allouis%2Fgit-internals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allouis%2Fgit-internals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allouis%2Fgit-internals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allouis%2Fgit-internals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allouis","download_url":"https://codeload.github.com/allouis/git-internals/tar.gz/refs/heads/gh-pages","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allouis%2Fgit-internals/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260690913,"owners_count":23047101,"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":[],"created_at":"2024-10-12T21:35:43.853Z","updated_at":"2026-02-02T11:01:33.279Z","avatar_url":"https://github.com/allouis.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git Internals\n \n ## What makes a git repository?\n \n To create a git repository you just need the `.git` directory in your project, with a few essential subdirectories and files.\n \n Those subdirectories and files are:\n \n - HEAD - This file tells git where the HEAD of your repo currently is, it points to a ref\n - /refs - This directory conatains all the refs, or pointers, to commits, e.g. branches, tags etc...\n - /objects - This directory is the database of git, its the storage part of the key-value store on which git sits \n\n## The storage mechanism\n \n You can think of git as a wrapper over a content addressable key-value store, there are three contents types: blobs, trees and commits.\n \n Essentially, a blob is a file, a tree is a directory, which contains blobs or other trees and a commit is metadata for a tree.\n \n Git stores all of this in the objects directory. The process for doing so is like:\n \n - Add a header to the content consisting of the content type (blob/tree/commit) the content length and a null byte.\n - Use a SHA1 hashing algorithm on the header + content\n - Use zlib defalte compression on the hash\n \n The resulting compressed string is then stored in the objects directory, using the first 2 chars of the hash as the sub dir and the remaining as the file name.\n \n Git internals give use a command that wraps this process up for us: `git hash-object`. We also get the reverse of this command, which takes a hash and gives us the content which is `git cat-file`\n\n## Creating trees\n \n A tree is simply a pointer to blobs and other trees, we can use the `git write-tree` command to take the current index and create a tree out of it. Our index can be thought of as staged changes. We can update the current index using the `git update-index` command, and using the `--cacheinfo` flag we pass it a filetype, a blob hash and a file name. This will create a `.git/index` file which contains the current state.\n \n Once we have the index in a state we would like to store as a tree, we can use `git write-tree`, this creates and stores a tree object and gives us back the hash for it.\n\n## Creating commits\n \n A commit is metadata about a specific tree, including the tree parent, the author of the commit and a description. We can create a commit at any point by use the `git commit-tree` command, this takes a tree hash and a description, we can also use the `-p` flag to pass the parent tree\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallouis%2Fgit-internals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallouis%2Fgit-internals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallouis%2Fgit-internals/lists"}