Skip to content

Leonardo-Garzon-1995/mygit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

113 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mygit

A simple version control system (git-like) implemented in JavaScript. 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 hash 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
  • ls-files - Show information about files in the index
  • tag - Create or list tags
  • diff - Show changes between commits, commit and working tree, or index and working tree
  • stash - Stash changes in a dirty working directory away

Other features include:

  • Support for .mygitignore files to exclude files from staging, status and diff operations

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

# 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 object
mygit write-tree

# Create commit from tree
mygit commit-tree <tree-hash> -m "Commit message" -p <parent-commit-optional>

Project Structure

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

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, stashes for temporary storage.
  • 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 an experimental project and is still in development and by no means it is 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 [email protected]

About

An implementation of git version control sytem in JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors