GitSlice CLI Development

sanjay

sanjay kumar

🧩 GitSlice CLI

A CLI tool to extract specific folders or file from GitHub repositories using sparse-checkout. Designed for speed, simplicity, and developers who don't want to clone massive repos unnecessarily.

πŸš€ Features

⚑️ Extract a specific folder or file from any GitHub repo
πŸ” Automatically resolves deep nested paths like /tree/branch/src/utils/
🌲 Uses Git sparse-checkout for minimal clone footprint
🧹 Cleans up temp files after extraction
πŸ”„ Supports both full clone and sparse mode
🧠 Intelligent path matching without needing full repo history

πŸ“¦ Installation

With Go

go install github.com/05sanjaykumar/gitslice@latest

Or clone and build:

git clone https://github.com/05sanjaykumar/gitslice
cd gitslice
go build -o gitslice main.go

πŸ› οΈ Usage

Basic Syntax

gitslice <github-folder-or-file-url>

Examples

gitslice https://github.com/supabase/storage/tree/fix/pgboss-on-error-callback/src/auth
gitslice https://github.com/vercel/next.js/tree/canary/packages/next
gitslice https://github.com/05sanjaykumar/Flappy-Bird-OpenCV/blob/main/assets/background-day.png

Output

Extracts folder/file to the current directory.
Auto-detects branch and path.

πŸ“‹ CLI Options

gitslice --help      # Show help
gitslice --version # Show version

🧠 How It Works

Parses the GitHub URL and extracts the owner, repo, branch, and folder or file path.
Clones the repo in sparse mode without full checkout.
Sets up sparse-checkout for the specific folder or file.
Switches to the correct branch and checks out only the required path.
Moves the folder or file to your working directory and cleans up.

πŸ†š GitSlice vs Manual Git Commands

With GitSlice ✨

gitslice https://github.com/user/repo/tree/branch/folder

Manual Git Way 😡

git clone --filter=blob:none --sparse https://github.com/user/repo
cd repo
git sparse-checkout init --cone
git sparse-checkout set folder
git checkout branch
cp -r folder ../
cd ..
rm -rf repo
GitSlice does in 1 command what takes 7 manual steps:
βœ… Parses GitHub URLs automatically
βœ… Handles branch detection
βœ… Sets up sparse-checkout configuration
βœ… Manages temporary directories
βœ… Cleans up after extraction
βœ… Works with both folders and individual files
βœ… Remembers the complex git syntax so you don't have to
Yes, GitSlice requires git to be installed - just like how npm requires Node.js, docker-compose requires Docker, and gh requires git. It's a productivity wrapper that makes complex git operations simple and accessible.

⚠️ Limitations & Edge Cases

Despite its power, GitSlice does have a few known limitations:
Branch-specific folders only: If a folder or a file exists only in a non-default branch (e.g., not in main), GitSlice might not detect or clone it correctly unless the branch is explicitly specified in the URL.
Private repositories: GitSlice currently only works with public GitHub repositories. Support for private repos (with authentication) is not yet implemented.
Path guessing limitations: The CLI resolves folder or file paths by pattern matching on local clone results. In very complex or dynamically generated repos, edge cases may slip through.
Shallow branch detection: We don't fetch the full remote branch list β€” only the default or specified branch is used for sparse-checkout. If you mistype the branch name or forget it in the URL, cloning will fail.
No submodule support (yet): Git submodules aren't handled or fetched. This tool assumes you're targeting standalone folders.
GitHub-only: Currently supports only GitHub URLs. Support for GitLab, Bitbucket, etc., is on the roadmap.

πŸ”’ Requirements

Git installed and available in PATH
Go 1.18+ (for building from source)

πŸ“„ License

MIT Β© Sanjay Kumar

❀️ Contributing

Pull requests and issues are welcome! If you hit an edge case or repo structure the tool doesn't support, open an issue and let’s improve it together.

Logo Image

Like this project

Posted Sep 25, 2025

Developed GitSlice CLI for efficient GitHub repo extraction.

Likes

0

Views

0

Timeline

Jun 30, 2025 - Jul 7, 2025