A simple version control system (git-like) implemented in JavaScript. 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 hash 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 objectls-files- Show information about files in the indextag- Create or list tagsdiff- Show changes between commits, commit and working tree, or index and working treestash- Stash changes in a dirty working directory away
Other features include:
- Support for
.mygitignorefiles to exclude files from staging, status and diff operations
- 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 object
mygit write-tree
# Create commit from tree
mygit commit-tree <tree-hash> -m "Commit message" -p <parent-commit-optional>mygit/
├── bin/
│ └── mygit.js # CLI entry point
├── src/
│ ├── commands/ # Command implementations
│ │ ├── init.js
│ │ ├── add.js
│ │ ├── commit.js
│ │ └── ...
│ ├── core/ # Core data structures and logic
│ ├── 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, stashes for temporary storage.
- 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 an experimental project and is still in development and by no means it is 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 [email protected]