BYOG is a minimal Git-like version control system built in Node.js to help you understand how Git works internally. This project is designed for learning purposes — by reading and running this project, you can see how commits, blobs, and trees are managed under the hood.
- Clone the repository:
git clone https://github.com/Abubakar00510/Byog-git_cloneAll BYOG commands are run using:
Windows:
.\byog byog <command> Linux / macOS:
./byog byog <command> BYOG mimics core Git functionality. Here’s an overview of the main components:
- The heart of BYOG. Manages:
- Initialization (
byog init) - Staging files (
addPath) - Creating trees (
createTree) - Committing changes (
commit) - Garbage collection (
gc)
- Initialization (
- Handles branch pointers and HEAD references.
- Blob (
blob.js) → Stores raw file content. - Tree (
tree.js) → Represents directories and maps file/directory names to hashes. - Commit (
commits.js) → Stores commit metadata: message, timestamp, tree hash, parent commits. - ByogObject (
byogObject.js) → Wrapper for serializing/deserializing objects for storage.
- Keeps track of staged files.
- Maps file paths to blob hashes.
- Read/Write operations to persist staging data.
- Provides colored console output for errors, info, and success messages.
- Low-level file system operations for storing and loading objects.
- Handles hashing and directory creation for objects.
- Parses user commands.
- Invokes Repository methods based on commands (
init,add,commit,gc,help). - Displays outputs to the console.
- Add files → Files are converted to blobs, saved in
.byog/objects, and indexed. - Commit → Tree objects are created recursively, commit object is stored, and branch updated.
- Garbage Collection → Removes unreferenced blob objects, keeps commits and trees intact.
.\byog byog init
██████╗ ██╗ ██╗ ██████╗ ██████╗
██╔══██╗██║ ██║██╔═══██╗██╔═══██╗
██████╔╝██║ ██║██║ ██║██║ ██║
██╔═══╝ ██║ ██║██║ ██║██║ ██║
██║ ╚██████╔╝╚██████╔╝╚██████╔╝
╚═╝ ╚═════╝ ╚═════╝ ╚═════╝
Welcome to BYOG - Build Your Own Git!
Initialized empty Byog repository in C:\Path\To\Repo\.byog
.\byog byog add file1.txt src/index.jsℹ️ Added: file1.txt
ℹ️ Added: src/index.js
.\byog byog commit -m "Initial commit"Created Commit <commit-hash> on branch master
Commit complete! All staged changes have been saved.
🔹 Exiting BYOG... See you next time! 🔹
.\byog byog gcℹ️ Garbage Collected: C:\Path\To\Repo\.byog\objects\9f\3a...
✅ Garbage collection complete.
.\byog byog helpBYOG Available Commands
byog init → Initialize a new repository
byog add <file> → Stage files for commit
byog commit -m "msg" → Commit staged changes
byog gc → Garbage collect loose objects
byog/
├── objects/
│ ├── blob.js
│ ├── tree.js
│ ├── commits.js
│ └── byogObject.js
├── utils/
│ └── logger.js
├── .byogignore
├── app.js
├── byog.bat
├── indexHandler.js
├── objectHandler.js
├── README.md
└── repository.js
The BYOG project is continuously evolving. Planned features include:
status→ View staged, unstaged, and untracked changescheckout→ Switch branches or revert to specific commitsbranch→ Create, list, and delete branches- Enhanced logging and error handling
- More Git-like commands to deepen understanding of version control internals
These features aim to make BYOG a more complete learning tool for developers who want to understand Git from the ground up.
By exploring BYOG, developers will learn:
- How Git stores objects (blobs, trees, commits)
- How staging and committing works internally
- How branches and HEAD references are managed
- How to implement a basic version control system from scratch
- How to apply Node.js for filesystem-based projects