https://github.com/mukailasam/snip
Snip is a command-line tool that lets you download a specific directory or file from a GitHub repository without cloning the entire project.
https://github.com/mukailasam/snip
cli directory download file folder github githubapi go repository snip tool
Last synced: 2 days ago
JSON representation
Snip is a command-line tool that lets you download a specific directory or file from a GitHub repository without cloning the entire project.
- Host: GitHub
- URL: https://github.com/mukailasam/snip
- Owner: mukailasam
- License: mit
- Created: 2025-10-16T16:44:43.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-10-16T17:33:46.000Z (8 months ago)
- Last Synced: 2025-10-17T20:16:29.420Z (8 months ago)
- Topics: cli, directory, download, file, folder, github, githubapi, go, repository, snip, tool
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# βοΈ Snip
```text
_____ _
/ ___| (_)
\ `--. _ __ _ _ __
`--. \ '_ \| | '_ \
/\__/ / | | | | |_) |
\____/|_| |_|_| .__/
| |
|_|
get just what you need.
```
[](https://go.dev/)
[](LICENSE)
[](https://goreportcard.com/report/github.com/mukailasam/snip)
Snip is a command-line tool that lets you download a specific folder or file from a GitHub repository without cloning the entire project.
_If you only need one example, one subfolder, or a single config file, Snip gets it for you directly._
## Features
- Download a specific folder or a single file
- Works for both public and private GitHub repositories
- No Git clone - uses the GitHub REST API directly
- Messages for rate limits and large repositories
- Automatically detects the repoβs default branch
- Built with [Cobra](https://github.com/spf13/cobra) for a clean CLI
## Installation
Install it from the sources:
```bash
git clone https://github.com/mukailasam/snip
cd snip
go install
```
Install it from the repository:
```bash
go install github.com/mukailasam/snip
```
## Usage
ποΈ Snip a folder
```
$ snip repo github.com/mukailasam/codelab --dir linear
```
π Snip a single file
```
$ snip repo github.com/mukailasam/codelab --file avl.go
```
π Specify a destination (optional)
```
$ snip repo github.com/mukailasam/codelab --dir array --dest /users/sam/desktop/workspace/temp
```
If you donβt specify a destination using --dest, Snip saves the result in your current working directory.
## π Private Repositories
To access private repositories, set your token via environment variable:
```
macOS / Linux (bash/zsh)
export GITHUB_TOKEN=ghp_xxxxxxxxx
Windows PowerShell
$env:GITHUB_TOKEN = "ghp_xxxxxxxxx"
```
Snip automatically detects your token and uses it for private repo access.
## Flags
Snip commands accept the following flags:
```text
| Flag | Description | Example |
|------------|--------------------------------------------------------------|----------------------|
| `--dir` | Name of the directory to snip from the repo | `--dir cmd` |
| `--file` | Name of the file to snip from the repo. | `--file go.mod` |
| `--branch` | Branch to use (optional). | `--branch main` |
| `--dest` | Destination directory to save downloaded content (optional). | `--dest ./downloads` |
```
## Project Structure
```text
cmd/
βββ helper.go
βββ root.go # Cobra CLI entrypoint
βββ repo.go # Handles 'snip repo' command
internal/
βββ provider/
β βββ github.go # GitHub API implementation
utils/
| βββ utils.go
main.go # Main entrypoint
```
## How Snip Works
- Parses the provided repo URL
- Detects whether the repo is public or private.
- Retrieves the default branch (if not specified).
- Lists all files and directories via GitHubβs Tree API
- Searches for the requested file or folder name.
- Downloads matching content into the specified (or default) destination.
Snip does not clone the repository or use Git β it talks directly to the providerβs REST API, keeping things lightweight and fast.
## Example Output
```
$ go run snip.go repo github.com/mukailasam/codelab --file avl.go
π Public repository detected.
π Listing repository tree for mukailasam/codelab (branch: main)...
β¬οΈ Downloaded: avl.go
β
Done.
```
## Why Snip?
Cloning an entire repository just to get one file or folder is inefficient.
Snip saves time, bandwidth, and storage by letting you fetch only what you need directly from the GitHub API.
Itβs perfect for developers who want a quick way to grab example files, configs, or small components without dealing with full clones or large repo histories.
## Inspiration
I needed a tool to quickly grab a single project, subfolder, configuration, or component from my Codelab without cloning the entire repository.
## Contributing
Contributions are welcome!
To contribute:
- Fork the repository
- Create a new branch
- Implement your feature or fix
- Open a pull request
Make sure to follow Goβs code formatting and keep your commits clean and descriptive.
## License
Snip is released under the MIT License. See LICENSE