Skip to content

Repository files navigation

GitLite

A lightweight Git-inspired version control system built in Java to understand the core concepts behind Git. GitLite implements repository initialization, content-addressable storage, staging, commits, branching, checkout, and status using Java and the Java NIO API.


Features

  • Initialize a GitLite repository
  • Stage files using SHA-1 hashing
  • Store blobs in an object database
  • Create commits with parent tracking
  • View commit history
  • Display repository status
  • Create and list branches
  • Switch between branches (checkout)
  • Automated unit testing with JUnit 5

Project Structure

.gitlite/
├── objects/      # Blob storage
├── commits/      # Commit objects
├── refs/         # Branch references
├── HEAD          # Current branch
└── index         # Staging area

Commands

Initialize a repository

.\gradlew.bat run --args="init"

Add a file

.\gradlew.bat run --args="add hello.txt"

Create a commit

.\gradlew.bat run --args="commit -m Initial"

View commit history

.\gradlew.bat run --args="log"

View repository status

.\gradlew.bat run --args="status"

Create a branch

.\gradlew.bat run --args="branch feature"

List branches

.\gradlew.bat run --args="branch"

Switch branches

.\gradlew.bat run --args="checkout feature"

How GitLite Works

Blob Storage

When a file is added:

  1. The file contents are read.
  2. A SHA-1 hash is generated.
  3. The contents are stored inside .gitlite/objects.
  4. The staging area (index) stores:
filename=sha1hash

Commit

Each commit stores:

  • Commit message
  • Timestamp
  • Parent commit ID
  • List of tracked files

Commits are stored inside:

.gitlite/commits/

Branches

Each branch is represented by a file inside:

.gitlite/refs/

The HEAD file stores the currently checked-out branch.


Technologies Used

  • Java 21
  • Gradle
  • Java NIO
  • SHA-1 Hashing
  • JUnit 5

Testing

Run all unit tests:

.\gradlew.bat test

The project includes automated tests for:

  • Repository initialization
  • File staging
  • Commit creation
  • Branch creation
  • Branch checkout

Future Improvements

Potential enhancements include:

  • Merge
  • Reset
  • Restore
  • Diff
  • Tags
  • Remote repositories
  • Push/Pull support

Repository Layout

GitLite
├── app/
├── gradle/
├── src/
├── .gitignore
├── README.md
├── build.gradle.kts
├── settings.gradle.kts
├── gradlew
└── gradlew.bat

Author

Aryaa Agarwal

Built as a learning project to understand how modern version control systems work internally.

About

Lightweight Git-inspired version control system built in Java.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages