Skip to content

Leonardo-Garzon-1995/mygit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mygit

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.

Features

Mygit supports the following commands:

  • init - Creates an empty mygit repository
  • add - Adds file contents to the staging area
  • commit - Records staged changes to the repository
  • log - Shows commit history with optional one-line format
  • branch - List, create, or delete branches
  • checkout - Switch branches or create new ones
  • status - Shows the current status of files
  • cat-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 file
  • write-tree - Create a tree object from the current index
  • commit-tree - Create a commit object from a tree
  • inspect-object - Show detailed information about any mygit object

Installation

Prerequisites

  • Node.js (version 14 or higher)

Install from source

git clone https://github.com/Leonardo-Garzon-1995/mygit.git
cd mygit
npm install
npm link

This will install mygit globally on your system, allowing you to use it from any directory.

Usage

Basic Workflow

  1. Initialize a repository:

    mygit init
  2. Add files to staging area:

    mygit add file.txt
    mygit add .  # Add all files
  3. Commit changes:

    mygit commit -m "Your commit message"
  4. View commit history:

    mygit log
    mygit log --oneline

Branching and Merging

# 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

Inspecting Objects

# 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>

Low-Level Operations

# 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>

Project Structure

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

Testing

Run the test suite:

npm test

Tests are written using Node.js built-in test runner and cover all major functionality.

How It Works

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: .mygit directory 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.

Contributing

Contributions are welcome! Areas for improvement:

  • Additional Git commands (merge, rebase, etc.)
  • Performance optimizations
  • Better error handling
  • More comprehensive tests

License

MIT LICENSE

Author

Leonardo Garzon lgarzonlc@gmail.com

About

An implementation of git version control sytem in JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors