Skip to content

mdpanchal21/Github-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


πŸ™ GitHub Clone

A full-stack GitHub-inspired platform built with the MERN stack β€” supporting real Git operations, issues, pull requests, commit history, branch management, and real-time notifications.


Warning

⚠️ Active Development Notice There are currently some known issues on the frontend side. I'm actively working on them in my free time. Feel free to open an issue β€” contributions, bug reports, and suggestions are always welcome! πŸ™Œ


πŸ“‹ Table of Contents


🌟 Overview

GitHub Clone is a self-hosted, open-source code collaboration platform. It replicates core GitHub workflows β€” from creating repositories and committing files to reviewing diffs, managing branches, raising issues, and merging pull requests β€” all powered by real Git internals via isomorphic-git and node-git-server.


πŸ›  Tech Stack

Frontend

Technology Purpose
React 19 UI framework
Vite 8 Development server & build tool
TailwindCSS 4 Utility-first styling
React Router DOM 7 Client-side routing
Socket.io Client Real-time notifications
Lucide React Icon library
React Markdown Render markdown files (README preview)
React Diff View Syntax-highlighted diff rendering
React Calendar Heatmap Contribution activity graph
Luxon Date/time formatting
Axios HTTP client

Backend

Technology Purpose
Node.js + Express 5 REST API server
MongoDB + Mongoose 9 Database & ODM
isomorphic-git Server-side Git operations (commit, diff, branches)
node-git-server Git HTTP smart protocol (clone, push, pull over HTTP)
Socket.io Real-time WebSocket events
JSON Web Token (JWT) Authentication & authorization
bcryptjs Password hashing
dotenv Environment variable management
fs-extra Enhanced file system operations
cors Cross-Origin Resource Sharing

✨ Features

  • πŸ” Authentication β€” Register, login, JWT-based session management
  • πŸ“ Repository Management β€” Create repos, browse file tree, view file contents
  • 🌿 Branch Management β€” Create branches, switch branches, compare refs
  • πŸ“ Commit System β€” Server-side commits via isomorphic-git, full commit log with diff view
  • πŸ”€ Pull Requests β€” Create PRs, view diffs between branches, check mergeability, merge
  • πŸ› Issues β€” Open issues, add comments, update open/closed status
  • πŸ“‘ Real-Time Notifications β€” Socket.io broadcasts when a PR is merged
  • πŸ‘€ Profile Page β€” View user profile and contribution graph
  • πŸ“„ README Preview β€” Auto-renders README.md on repo home page
  • 🌐 Git over HTTP β€” Real git clone, git push, git pull via the /git endpoint

πŸ“‚ Project Structure

github-clone/
β”œβ”€β”€ client/                   # React frontend (Vite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Navbar.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Register.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ RepoView.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ FileExplorer.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ CommitHistory.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ DiffView.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ IssueList.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ IssueDetail.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ PullRequestList.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ PullRequestDetails.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ CreatePullRequest.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ CreateRepoModal.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ProfilePage.jsx
β”‚   β”‚   β”‚   └── ContributionGraph.jsx
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   └── main.jsx
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.js
β”‚
β”œβ”€β”€ server/                   # Express backend
β”‚   β”œβ”€β”€ controllers/          # Business logic
β”‚   β”œβ”€β”€ middleware/           # Auth middleware (JWT)
β”‚   β”œβ”€β”€ models/               # Mongoose schemas
β”‚   β”‚   β”œβ”€β”€ User.js
β”‚   β”‚   β”œβ”€β”€ Repository.js
β”‚   β”‚   β”œβ”€β”€ Issue.js
β”‚   β”‚   └── PullRequest.js
β”‚   β”œβ”€β”€ routes/               # API route definitions
β”‚   β”‚   β”œβ”€β”€ authRoutes.js
β”‚   β”‚   β”œβ”€β”€ repoRoutes.js
β”‚   β”‚   β”œβ”€β”€ issueRoutes.js
β”‚   β”‚   └── userRoutes.js
β”‚   β”œβ”€β”€ gitServer.js          # node-git-server config
β”‚   └── index.js              # Entry point
β”‚
└── repositories/             # Bare Git repos (auto-created)

βœ… Prerequisites

Make sure the following are installed on your system before proceeding:

  • Node.js >= 18.x β€” Download
  • npm >= 9.x (comes with Node.js)
  • Git >= 2.x β€” Download
  • MongoDB β€” Either local install or a free MongoDB Atlas cluster

πŸ” Environment Setup

Server β€” server/.env

Create a .env file inside the server/ directory:

# ─── Server ────────────────────────────────────────────────
PORT=5000

# ─── MongoDB ───────────────────────────────────────────────
# Option 1: Local MongoDB
MONGODB_URI=mongodb://localhost:27017/github-clone

# Option 2: MongoDB Atlas (recommended)
MONGODB_URI=mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/github-clone?retryWrites=true&w=majority

# ─── JWT ───────────────────────────────────────────────────
JWT_SECRET=your_super_secret_key_change_this_in_production
JWT_EXPIRES_IN=7d
Variable Required Description
PORT No Port for Express server. Defaults to 5000
MONGODB_URI Yes MongoDB connection string
JWT_SECRET Yes Secret key for signing JWT tokens. Use a long random string in production
JWT_EXPIRES_IN No Token expiry duration. Defaults to 7d

Tip

Generate a strong JWT secret with: node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"

Client β€” client/.env

# ─── Backend Base URL ──────────────────────────────────────
VITE_API_BASE_URL=http://localhost:5000

Note

If you change the server port, update VITE_API_BASE_URL and the Socket.io connection URL in client/src/App.jsx accordingly.


πŸš€ Installation & Running

1. Clone the Repository

git clone https://github.com/<your-username>/github-clone.git
cd github-clone

2. Install Dependencies

# Install server dependencies
cd server
npm install

# Install client dependencies
cd ../client
npm install

3. Create the Repositories Storage Directory

The git server stores bare repos here. Create it at the project root:

mkdir -p ../repositories

4. Start the Backend

cd server
node index.js

Expected output:

MongoDB Connected
Server is running on port 5000

5. Start the Frontend

Open a new terminal tab:

cd client
npm run dev

Expected output:

  VITE v8.x.x  ready in xxx ms

  ➜  Local:   http://localhost:5173/

Open http://localhost:5173 in your browser.


πŸ“‘ API Reference

All API endpoints are prefixed with /api/v1. Protected routes require an Authorization: Bearer <token> header.

Auth

Method Endpoint Auth Description
POST /api/v1/auth/signup ❌ Register a new user
POST /api/v1/auth/login ❌ Login and receive a JWT token

Repositories

Method Endpoint Auth Description
POST /api/v1/repos/init βœ… Initialize a new repository
GET /api/v1/repos/user/mine βœ… List current user's repositories
GET /api/v1/repos/:repoId ❌ Get repository details
GET /api/v1/repos/:repoId/files ❌ List all files in HEAD branch
POST /api/v1/repos/:repoId/commit βœ… Write, stage, and commit changes
GET /api/v1/repos/:repoId/commits ❌ Get full commit history
GET /api/v1/repos/:repoId/commits/:sha/diff ❌ Get diff for a specific commit
GET /api/v1/repos/:repoId/branches ❌ List all branches
POST /api/v1/repos/:repoId/branches βœ… Create a new branch
GET /api/v1/repos/:repoId/compare/:base/:head ❌ Compare two branches

Pull Requests

Method Endpoint Auth Description
GET /api/v1/repos/:repoId/prs ❌ List all pull requests
POST /api/v1/repos/:repoId/prs βœ… Create a new pull request
GET /api/v1/repos/:repoId/prs/:prId/mergeable ❌ Check if PR is mergeable
POST /api/v1/repos/:repoId/prs/:prId/merge βœ… Merge a pull request

Issues

Method Endpoint Auth Description
POST /api/v1/issues/:repositoryId βœ… Open a new issue
GET /api/v1/issues/repo/:repoId ❌ List all issues for a repo
GET /api/v1/issues/:issueId ❌ Get issue details & comments
POST /api/v1/issues/:issueId/comments βœ… Add a comment to an issue
PATCH /api/v1/issues/:issueId/status βœ… Update issue status (open/closed)

Users

Method Endpoint Auth Description
GET /api/v1/users/:username ❌ Get public profile of a user

🌐 Git Operations

This project supports real Git operations over HTTP using the Git smart HTTP protocol.

Once a repository is created via the API, you can interact with it using standard Git commands:

# Clone a repository
git clone http://localhost:5000/git/<repo-name>

# Add a remote to an existing local repo
git remote add origin http://localhost:5000/git/<repo-name>

# Push changes
git push origin main

# Pull latest changes
git pull origin main

Note

<repo-name> refers to the bare repository name stored in the repositories/ directory on the server. This is initialized automatically when you create a repo via the API.


⚑ Real-Time Events (Socket.io)

The server uses Socket.io for real-time communication. The client connects to http://localhost:5000 on app load.

Event Direction Description
join_repo Client β†’ Server Join a repository's room to receive its events
pr_merged Server β†’ Client Emitted to all room members when a PR is merged

🀝 Contributing

Contributions are welcome! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feat/amazing-feature
  3. Commit your changes: git commit -m "feat: add amazing feature"
  4. Push to the branch: git push origin feat/amazing-feature
  5. Open a Pull Request on GitHub

Reporting Bugs

Found a bug or a frontend issue? Please open an issue with:

  • A clear title and description
  • Steps to reproduce
  • Expected vs. actual behavior
  • Screenshots if applicable

Note

There are currently some known issues on the frontend side. I'm working on them in my free time β€” feel free to open an issue or submit a PR if you spot something! πŸ™Œ


πŸ“œ License

This project is open-source and available under the MIT License.


Built with ❀️ as a learning project β€” inspired by GitHub.

About

A full-stack GitHub-inspired code collaboration platform built with the MERN stack. Features real Git operations (commits, branches, merges), Issues, Pull Requests, and Git over HTTP functionality. Powered by Node.js, React, and Socket.io.

Topics

Resources

Stars

Watchers

Forks

Contributors