A simple version control system (git-like) implemented in JavaScript, designed to demonstrate how Git works internally. This project implements core Git functionality including repository initialization, staging, committing, branching, and more.
Mygit supports the following commands:
init- Creates an empty mygit repositoryadd- Adds file contents to the staging areacommit- Records staged changes to the repositorylog- Shows commit history with optional one-line formatbranch- List, create, or delete branchescheckout- Switch branches or create new onesstatus- Shows the current status of filescat-file- Display information about repository objects (-t type, -s size, -p pretty-print)hash-object- Compute object ID and optionally create a blob from a filewrite-tree- Create a tree object from the current indexcommit-tree- Create a commit object from a treeinspect-object- Show detailed information about any mygit object
- Node.js (version 14 or higher)
git clone https://github.com/Leonardo-Garzon-1995/mygit.git
cd mygit
npm install
npm linkThis will install mygit globally on your system, allowing you to use it from any directory.
-
Initialize a repository:
mygit init
-
Add files to staging area:
mygit add file.txt mygit add . # Add all files
-
Commit changes:
mygit commit -m "Your commit message" -
View commit history:
mygit log mygit log --oneline
# List branches
mygit branch
# Create and switch to a new branch
mygit checkout -b feature-branch
# Switch to existing branch
mygit checkout main
# Delete a branch
mygit branch -d feature-branch# Show object type
mygit cat-file -t <object-hash>
# Show object size
mygit cat-file -s <object-hash>
# Pretty-print object content
mygit cat-file -p <object-hash>
# Detailed object inspection
mygit inspect-object <object-hash># Hash a file (create blob object)
mygit hash-object file.txt
# Create tree from index
mygit write-tree
# Create commit from tree
mygit commit-tree <tree-hash> -m "Commit message" -p <parent-commit>mygit/
├── bin/
│ └── mygit.js # CLI entry point
├── src/
│ ├── commands/ # Command implementations
│ │ ├── init.js
│ │ ├── add.js
│ │ ├── commit.js
│ │ └── ...
│ ├── core/
│ ├── helpers/ # Git functionality helpers
│ └── utils/ # Utility functions
├── tests/ # Test files
├── z-explanation/ # Educational documentation
└── package.json
Run the test suite:
npm testTests are written using Node.js built-in test runner and cover all major functionality.
Mygit implements Git's core concepts:
- Objects: Blobs (files), Trees (directories), and Commits
- References: Branches and HEAD pointing to commits
- Index/Staging Area: Tracks files ready for commit
- Repository Structure:
.mygitdirectory containing all metadata
Each command manipulates these core data structures to provide version control functionality. The z-explanation/ directory contains detailed documentation explaining how each feature works internally.
Mygit is still in development and it is not meant to be use as a production-ready product.
Contributions are welcome! Areas for improvement:
- Additional Git commands (merge, rebase, etc.)
- Performance optimizations
- Better error handling
- More comprehensive tests
MIT LICENSE
Leonardo Garzon lgarzonlc@gmail.com