A high-performance, from-scratch implementation of Git written in C++. This project builds a functional VCS client capable of low-level object manipulation, parsing binary packfiles, resolving delta-compressed objects, and executing a custom cryptographic signing layer to ensure commit authenticity and tamper-proofing.
- Low-Level Object Storage: Implements blob creation, tree serialization, and commit generation, using SHA-1 hashing and Zlib compression.
- Smart HTTP Client: Connects directly to Git remotes using the Git Smart HTTP Protocol to perform repository cloning.
- Packfile Parsing: Parses binary packfiles, decoding variable-length integers and resolving delta-compressed objects (
OBJ_REF_DELTAandOBJ_OFS_DELTA). - Cryptographic Security Layer: Custom RSA public-key cryptography integration to sign commits and verify history integrity.
To prevent attackers from rewriting repository history and computing new SHAs, this VCS implements an asymmetric cryptographic signing and verification flow:
- Key Generation: Generates 2048-bit RSA public/private key pairs and stores them securely in PEM format.
- State Serialization: Gathers commit metadata (tree, parent, author, committer, and message) into a canonical text representation.
- Commit Hashing: Hashes the serialized state using SHA-256 to generate a tamper-proof commit fingerprint.
- Asymmetric Signing: Encrypts the SHA-256 fingerprint using the user's RSA private key. The resulting digital signature is appended directly to the commit object under a custom
gpgsigheader. - The Verification Loop:
- Reads the commit object, extracts the
gpgsigsignature, and reconstructs the unsigned metadata. - Re-computes the SHA-256 hash of the metadata.
- Decrypts the signature using the author's public key and verifies that the decrypted fingerprint matches the computed hash. Any alteration to the parent commits, files, author info, or commit message fails verification immediately.
- Reads the commit object, extracts the
Bandwidth-efficient cloning is achieved by manually parsing the Git binary packfile format:
- Extracts pack headers containing object counts.
- Sequentially decompresses compressed objects using Zlib.
- Resolves delta dependencies by applying binary patching instructions (Copy/Insert commands) against base objects dynamically.
- C++ Compiler supporting C++23.
- Zlib for compression (
-lz). - OpenSSL (v3.0+) for cryptographic signing and hashing (
-lcrypto).
Build using CMake:
cmake -B build -S .
cmake --build ./buildInitializes a new directory structure for VCS objects and references.
./build/git initGenerates private and public key files at .git/private_key.pem and .git/public_key.pem for signing and verification.
./build/git keygenHash a file and store it in the database:
./build/git hash-object -w <file_path>Recursively write the current directory to a Git tree object:
./build/git write-treeIf .git/private_key.pem is found, the commit will be automatically signed. Alternatively, specify the path to a private key:
./build/git commit-tree <tree_sha> -m "My commit message" [--sign <private_key_path>]Validates that the commit signature matches the public key and that the commit has not been altered:
./build/git verify-commit <commit_sha> [--key <public_key_path>]Downloads a repository from a remote URL over HTTP:
./build/git clone <url> <target_directory>