🏗️ Fetch a specific commit without any history (shallow depth w/o cloning)

shallow-fetch-sha 🏗️

For a given git repository and commit, fetch and checkout just that commit without any history. This can be extremely useful in CI/CD systems that need to ship code from repositories with large ref/object history and only need files at a specific commit.

Effectively the same as the following on a given directory:

you@local:~$ git init
you@local:~$ git remote add origin $REPO
you@local:~$ git fetch --depth 1 origin $SHA
you@local:~$ git checkout $SHA

Credit to sschuberth from StackOverflow

This utility is shipped as a standalone binary as well as a container. It is built using go-git, a pure Go implementation of git.

Note: this is only compatible with Git servers >= 2.50, since they must support (and enable) uploadpack.allowReachableSHA1InWant.

Usage

CLI (standalone binary)

you@local:~$ shallow-fetch-sha --help
For a given git repository and commit sha, fetch and checkout a specific commit
to save time and networking traffic. The resulting directory will not have any
ref/object history beyond the specified commit sha.

The repository can be specified as either SSH or HTTPS, but the commit must be
the 40 digit hexadecimal SHA1 representation.

Both SSH and Basic authentication are supported, granted the proper repository
URLs are specified. This program does not honor git-config files or options.

Note: this is only compatible with Git servers >= 2.50, they must support and
enable the 'uploadpack.allowReachableSHA1InWant' configuration option.

Usage:
  shallow-fetch-sha <repo> <sha> [flags]

Flags:
  -d, --directory string        working directory for the repository (default ".")
  -u, --username string         username for basic authentication
  -p, --password string         password for basic authentication
  -i, --key-path string         pem encoded private key file for ssh authentication
  -P, --key-passphrase string   private key passphrase for ssh authentication
      --rm-dotgit               remove the '.git' directory after pulling files
  -v, --verbose                 verbose output
  -h, --help                    help for shallow-fetch-sha

Container

The entrypoint is the shallow-fetch-sha binary, and the default working directory is /usr/src/repo. The user is the default non-priviledged guest (uid=405) user within the alpine image.

Basic usage:

you@local:~$ podman run -it registry.tbd/robherley/shallow-fetch-sha:$TAG <repo> <sha> [flags]

Fetching a repo/commit and saving to a local directory:

you@local:~$ podman run -it --rm -v $(pwd)/repo:/usr/src/repo registry.tbd/robherley/shallow-fetch-sha:$TAG https://github.com/robherley/reb.gg fd40042f1a21da61b4abddebbe94f21dc700ffb0
INFO[0000] shallow fetching repository                   dir=/usr/src/repo sha=fd40042f1a21da61b4abddebbe94f21dc700ffb0
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (3/3), done.
Total 4 (delta 0), reused 3 (delta 0), pack-reused 0
Similar Resources

Pure Go command line prompt with history, kill-ring, and tab completion

Prompt Prompt is a command line prompt editor with history, kill-ring, and tab completion. It was inspired by linenoise and derivatives which eschew u

Nov 20, 2021

A simple CLI tool that outputs the history of connections to Amazon EC2 instances using AWS Session Manager.

ssmh This is a simple CLI tool that outputs the history of connections to Amazon EC2 instances using AWS Session Manager. Installation brew install mi

Dec 10, 2021

Alfred workfow for search safari history.

Alfred workfow for search safari history.

Alfred Safari Toolkit This is an Alfred workflow for Safari. I have been using tupton/alfred-safari-history for years, but it runs with Python2 which

Dec 17, 2022

A command line utility for generating language-specific project structure.

A command line utility for generating language-specific project structure.

hydra hydra is a command line utility for generating language-specific project structures. ⏬ ✨ Features Build project templates with just one command

Oct 8, 2021

Github user stats fetch written in golang

Github user stats fetch written in golang

TACOMA It's like neofetch, but for github users. I saw something similar on reddit and decided to recreate it using only golang. Original inspiration:

Dec 24, 2021

Fetch All Links And Compare From Prior Fetches For golang

Fetch All Links And Compare From Prior Fetches This program can be run with go r

Jan 1, 2022

Pi-fetch - get a summary of your pi-hole stats from your terminal

pi-fetch get a summary of your pi-hole stats from your terminal _ ___ _ _ ___|_|___| _|___| |_ ___| |_ | . | |___| _| -_| _

Jan 9, 2022

Go-api-cli - Small CLI to fetch data from an API sync and async

Async API Cli CLI to fetch data on "todos" from a given API in a number of ways.

Jan 13, 2022

Yaf - Yet another system fetch that is minimal and customizable

Yaf - Yet another system fetch that is minimal and customizable

Yaf - Yet Another Fetch [Support] [Installation] [Usage] Brief Yet Another Fetch

Oct 11, 2022
🚀 Get Youtube Live stream chat feed without any authentication!

youtube-live-chat-downloader Fetches Youtube live chat messages with no authentication required. How does it work? The request for fetching live chat

Oct 17, 2022
The runner project is to create an interface for users to run their code remotely without having to have any compiler on their machine
The runner project is to create an interface for users to run their code remotely without having to have any compiler on their machine

The runner project is to create an interface for users to run their code remotely without having to have any compiler on their machine. This is a work in progress project for TCSS 401X :)

May 29, 2022
Godbolt console wrapper for easily execute local file without any security risk and compiler.

Godbolt CLI Godbolt console wrapper for easily execute local file without any security risk and compiler. Install Compile the source code and add to y

May 22, 2022
commit/branch/workdir explorer for git

gitin gitin is a commit/branch/status explorer for git gitin is a minimalist tool that lets you explore a git repository from the command line. You ca

Dec 21, 2022
A CLI to replace your git commit command, so your git message can partially follow the Conventional Changelog ecosystem
A CLI to replace your git commit command, so your git message can partially follow the Conventional Changelog ecosystem

COMMIT CLI A CLI to replace your git commit command, so your git message can partially follow the Conventional Changelog ecosystem. And yes, it is bui

Feb 9, 2022
Pure Go line editor with history, inspired by linenoise

Liner Liner is a command line editor with history. It was inspired by linenoise; everything Unix-like is a VT100 (or is trying very hard to be). If yo

Jan 3, 2023
Pi-hole data right from your terminal. Live updating view, query history extraction and more!
Pi-hole data right from your terminal. Live updating view, query history extraction and more!

Pi-CLI Pi-CLI is a command line program used to view data from a Pi-Hole instance directly in your terminal.

Dec 12, 2022
Integrated console application library, using Go structs as commands, with menus, completions, hints, history, Vim mode, $EDITOR usage, and more ...
Integrated console application library, using Go structs as commands, with menus, completions, hints, history, Vim mode, $EDITOR usage, and more ...

Gonsole - Integrated Console Application library This package rests on a readline console library, (giving advanced completion, hint, input and histor

Nov 20, 2022
A sample FaaS function that gets a stock quote and 30 day history by symbol and returns a HTML page with a generates SVG sparkline.

faas stonks This uses serverless technology to get a stock quote and 30 day sparkline from Yahoo Finance. Deployment Nimbella account Namespace with o

Sep 23, 2021
Create new commands from your shell history or terminal.

overdub Create new commands from your shell history or terminal. TODO list for initial release Filter out unlikely commands (e.g. package managers) fr

Aug 9, 2022